mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-22 12:36:24 +08:00
refactor!: next generation AFFiNE code structure (#1176)
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
import { PermissionType } from '@affine/datacenter';
|
||||
|
||||
import { AffineOfficialWorkspace } from '../../shared';
|
||||
|
||||
export function useIsWorkspaceOwner(workspace: AffineOfficialWorkspace) {
|
||||
if (workspace.flavour === 'local') return true;
|
||||
return workspace.permission === PermissionType.Owner;
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import { Member } from '@affine/datacenter';
|
||||
import { useCallback } from 'react';
|
||||
import useSWR from 'swr';
|
||||
|
||||
import { QueryKey } from '../../plugins/affine/fetcher';
|
||||
import { apis } from '../../shared/apis';
|
||||
|
||||
export function useMembers(workspaceId: string) {
|
||||
const { data, mutate } = useSWR<Member[]>(
|
||||
[QueryKey.getMembers, workspaceId],
|
||||
{
|
||||
fallbackData: [],
|
||||
}
|
||||
);
|
||||
|
||||
const inviteMember = useCallback(
|
||||
async (email: string) => {
|
||||
await apis.inviteMember({
|
||||
id: workspaceId,
|
||||
email,
|
||||
});
|
||||
return mutate();
|
||||
},
|
||||
[mutate, workspaceId]
|
||||
);
|
||||
|
||||
const removeMember = useCallback(
|
||||
async (permissionId: number) => {
|
||||
// fixme: what about the workspaceId?
|
||||
await apis.removeMember({
|
||||
permissionId,
|
||||
});
|
||||
return mutate();
|
||||
},
|
||||
[mutate]
|
||||
);
|
||||
|
||||
return {
|
||||
members: data ?? [],
|
||||
inviteMember,
|
||||
removeMember,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import { useCallback } from 'react';
|
||||
import { mutate } from 'swr';
|
||||
|
||||
import { QueryKey } from '../../plugins/affine/fetcher';
|
||||
import { AffineRemoteWorkspace } from '../../shared';
|
||||
import { apis } from '../../shared/apis';
|
||||
import { refreshDataCenter } from '../use-workspaces';
|
||||
|
||||
export function useToggleWorkspacePublish(workspace: AffineRemoteWorkspace) {
|
||||
return useCallback(
|
||||
async (isPublish: boolean) => {
|
||||
await apis.updateWorkspace({
|
||||
id: workspace.id,
|
||||
public: isPublish,
|
||||
});
|
||||
await mutate(QueryKey.getWorkspaces);
|
||||
await refreshDataCenter();
|
||||
},
|
||||
[workspace]
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import useSWR from 'swr';
|
||||
|
||||
import { QueryKey } from '../../plugins/affine/fetcher';
|
||||
|
||||
export interface QueryEmailMember {
|
||||
id: string;
|
||||
name: string;
|
||||
email: string;
|
||||
avatar_url: string;
|
||||
create_at: string;
|
||||
}
|
||||
|
||||
export function useUsersByEmail(
|
||||
workspaceId: string,
|
||||
email: string
|
||||
): QueryEmailMember[] | null {
|
||||
const { data } = useSWR<QueryEmailMember[] | null>(
|
||||
[QueryKey.getUserByEmail, workspaceId, email],
|
||||
{
|
||||
fallbackData: null,
|
||||
}
|
||||
);
|
||||
return data ?? null;
|
||||
}
|
||||
Reference in New Issue
Block a user