diff --git a/jsapp/js/account/organization/membersQuery.ts b/jsapp/js/account/organization/membersQuery.ts index 1bec128e80..9414c796bd 100644 --- a/jsapp/js/account/organization/membersQuery.ts +++ b/jsapp/js/account/organization/membersQuery.ts @@ -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'; @@ -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 +) { + const apiUrl = endpoints.ORGANIZATION_MEMBER_URL + .replace(':organization_id', organizationId) + .replace(':username', username); + return fetchPatch(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 diff --git a/jsapp/js/account/organization/organizationQuery.ts b/jsapp/js/account/organization/organizationQuery.ts index 70f499b09a..dc1f3989d8 100644 --- a/jsapp/js/account/organization/organizationQuery.ts +++ b/jsapp/js/account/organization/organizationQuery.ts @@ -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', diff --git a/jsapp/js/api.endpoints.ts b/jsapp/js/api.endpoints.ts index a6096989f1..d07960d7f5 100644 --- a/jsapp/js/api.endpoints.ts +++ b/jsapp/js/api.endpoints.ts @@ -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 **/