mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-16 17:46:18 +08:00
5870a6097a
* Chore/unit test (#538) * chore: add unit test * chore: add github action for unit test * feat: init firebase * chore: add development secrets * fix: rename auth -> data-services * feat: update blocksuite 0.3.0-alpha.4 (#543) * feat: add requests * feat: optimize swr cache * feat: add Authorization * feat: add confirm-invitation page * feat: add account sdk api and proxy * docs: update contributing (#550) * docs: update contributing * Update CONTRIBUTING.md * Update CONTRIBUTING.md Co-authored-by: ShortCipher5 <me@shortcipher.me> * feat: update api * feat: remove babelrc setting * feat: add create workspace ui * feat: choose workspaces * feat: login modal * feat: authorization api * feat: login status * fix: remove unused variables * feat: login button * fix: lint * fix: workspace id * fix: i18n type error Co-authored-by: MingLiang Wang <mingliangwang0o0@gmail.com> Co-authored-by: ShortCipher5 <me@shortcipher.me>
91 lines
2.1 KiB
TypeScript
91 lines
2.1 KiB
TypeScript
import useSWR, { SWRConfiguration } from 'swr';
|
|
import { request, ServiceError } from '../request';
|
|
import type {
|
|
RequestAcceptInviting,
|
|
RequestInviteCollaborator,
|
|
RequestRemoveCollaborator,
|
|
ResponseInviteCollaborator,
|
|
} from './types';
|
|
|
|
const COLLABORATOR_INVITE_URL = '/api/account/invite';
|
|
const REMOVE_COLLABORATOR_URL = '/api/account/remove_collaborator';
|
|
|
|
async function doInviteCollaborator(
|
|
url: string,
|
|
req: RequestInviteCollaborator
|
|
) {
|
|
const { data } = await request.post<ResponseInviteCollaborator>(url, req);
|
|
return data;
|
|
}
|
|
|
|
export async function inviteCollaborator(req: RequestInviteCollaborator) {
|
|
return await doInviteCollaborator(COLLABORATOR_INVITE_URL, req);
|
|
}
|
|
|
|
async function doRemoveCollaborator(
|
|
url: string,
|
|
req: RequestRemoveCollaborator
|
|
) {
|
|
return request.post(url, req);
|
|
}
|
|
|
|
export async function removeCollaborator(req: RequestRemoveCollaborator) {
|
|
return await doRemoveCollaborator(REMOVE_COLLABORATOR_URL, req);
|
|
}
|
|
|
|
function doAcceptInviting(url: string, req: RequestAcceptInviting) {
|
|
return request.post(url, req);
|
|
}
|
|
|
|
export async function acceptInviting(req: RequestAcceptInviting) {
|
|
return await doAcceptInviting(COLLABORATOR_INVITE_URL, req);
|
|
}
|
|
|
|
export function useInviteCollaborator(
|
|
req: RequestInviteCollaborator,
|
|
config?: SWRConfiguration
|
|
) {
|
|
const { data, error } = useSWR<ResponseInviteCollaborator, ServiceError>(
|
|
[COLLABORATOR_INVITE_URL, req],
|
|
doInviteCollaborator,
|
|
config
|
|
);
|
|
return {
|
|
data,
|
|
isLoading: !error && !data,
|
|
isError: error,
|
|
};
|
|
}
|
|
|
|
export function useRemoveCollaborator(
|
|
req: RequestRemoveCollaborator,
|
|
config?: SWRConfiguration
|
|
) {
|
|
const { data, error } = useSWR<unknown, ServiceError>(
|
|
[REMOVE_COLLABORATOR_URL, req],
|
|
doRemoveCollaborator,
|
|
config
|
|
);
|
|
return {
|
|
data,
|
|
isLoading: !error && !data,
|
|
isError: error,
|
|
};
|
|
}
|
|
|
|
export function useAcceptInviting(
|
|
req: RequestAcceptInviting,
|
|
config?: SWRConfiguration
|
|
) {
|
|
const { data, error } = useSWR<unknown, ServiceError>(
|
|
[COLLABORATOR_INVITE_URL, req],
|
|
doAcceptInviting,
|
|
config
|
|
);
|
|
return {
|
|
data,
|
|
isLoading: !error && !data,
|
|
isError: error,
|
|
};
|
|
}
|