Skip to content

Commit

Permalink
Merge branch 'leszek/task-985-member-mutation-api' into task-987-memb…
Browse files Browse the repository at this point in the history
…ers-table-actions-dropdown
  • Loading branch information
magicznyleszek authored Nov 29, 2024
2 parents 126f000 + 3e9048e commit 03c90c0
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
30 changes: 29 additions & 1 deletion jsapp/js/account/organization/membersQuery.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {keepPreviousData, useQuery} from '@tanstack/react-query';
import {endpoints} from 'js/api.endpoints';
import type {PaginatedResponse} from 'js/dataInterface';
import {fetchGet} from 'js/api';
import {fetchGet, fetchPatch, fetchDelete} from 'js/api';
import {QueryKeys} from 'js/query/queryKeys';
import {useOrganizationQuery, type OrganizationUserRole} from './organizationQuery';

Expand Down Expand Up @@ -34,6 +34,34 @@ export interface OrganizationMember {
};
}

/**
* For updating member within given organization. Accepts partial properties
* of `OrganizationMember`.
*/
export async function patchOrganizationMember(
organizationId: string,
username: string,
newMemberData: Partial<OrganizationMember>
) {
const apiUrl = endpoints.ORGANIZATION_MEMBER_URL
.replace(':organization_id', organizationId)
.replace(':username', username);
return fetchPatch<OrganizationMember>(apiUrl, newMemberData);
}

/**
* For removing member from given organization.
*/
export async function removeOrganizationMember(
organizationId: string,
username: string
) {
const apiUrl = endpoints.ORGANIZATION_MEMBER_URL
.replace(':organization_id', organizationId)
.replace(':username', username);
return fetchDelete(apiUrl);
}

/**
* Fetches paginated list of members for given organization.
* This is mainly needed for `useOrganizationMembersQuery`, so you most probably
Expand Down
4 changes: 4 additions & 0 deletions jsapp/js/account/organization/organizationQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ export interface Organization {
request_user_role: OrganizationUserRole;
}

/**
* Note that it's only possible to update the role via API to either `admin` or
* `member`.
*/
export enum OrganizationUserRole {
member = 'member',
admin = 'admin',
Expand Down
1 change: 1 addition & 0 deletions jsapp/js/api.endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const endpoints = {
SUBSCRIPTION_URL: '/api/v2/stripe/subscriptions/',
ADD_ONS_URL: '/api/v2/stripe/addons/',
ORGANIZATION_MEMBERS_URL: '/api/v2/organizations/:organization_id/members/',
ORGANIZATION_MEMBER_URL: '/api/v2/organizations/:organization_id/members/:username/',
/** Expected parameters: price_id and organization_id **/
CHECKOUT_URL: '/api/v2/stripe/checkout-link',
/** Expected parameter: organization_id **/
Expand Down

0 comments on commit 03c90c0

Please sign in to comment.