Multitenancy support
This commit is contained in:
@@ -1,2 +1,6 @@
|
||||
export { useCreateDomain, type CreateDomainParams } from './useCreateDomain';
|
||||
export { useDeleteDomain } from './useDeleteDomain';
|
||||
export { useDomains } from './useDomains';
|
||||
export { useSuggest } from './useSuggest';
|
||||
export { useUpdateDomain } from './useUpdateDomain';
|
||||
export { useVerify } from './useVerify';
|
||||
23
src/api/hooks/admin/useCreateDomain.ts
Normal file
23
src/api/hooks/admin/useCreateDomain.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { Entities } from 'soapbox/entity-store/entities';
|
||||
import { useCreateEntity } from 'soapbox/entity-store/hooks';
|
||||
import { useApi } from 'soapbox/hooks';
|
||||
import { domainSchema } from 'soapbox/schemas';
|
||||
|
||||
interface CreateDomainParams {
|
||||
domain: string;
|
||||
public: boolean;
|
||||
}
|
||||
|
||||
const useCreateDomain = () => {
|
||||
const api = useApi();
|
||||
|
||||
const { createEntity, ...rest } = useCreateEntity([Entities.DOMAINS], (params: CreateDomainParams) =>
|
||||
api.post('/api/v1/pleroma/admin/domains', params), { schema: domainSchema });
|
||||
|
||||
return {
|
||||
createDomain: createEntity,
|
||||
...rest,
|
||||
};
|
||||
};
|
||||
|
||||
export { useCreateDomain, type CreateDomainParams };
|
||||
26
src/api/hooks/admin/useDeleteDomain.ts
Normal file
26
src/api/hooks/admin/useDeleteDomain.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { Entities } from 'soapbox/entity-store/entities';
|
||||
import { useDeleteEntity } from 'soapbox/entity-store/hooks';
|
||||
import { useApi } from 'soapbox/hooks';
|
||||
|
||||
interface DeleteDomainParams {
|
||||
domain: string;
|
||||
public: boolean;
|
||||
}
|
||||
|
||||
const useDeleteDomain = () => {
|
||||
const api = useApi();
|
||||
|
||||
const { deleteEntity, ...rest } = useDeleteEntity(Entities.DOMAINS, (id: string) =>
|
||||
api.delete(`/api/v1/pleroma/admin/domains/${id}`, {
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data',
|
||||
},
|
||||
}));
|
||||
|
||||
return {
|
||||
mutate: deleteEntity,
|
||||
...rest,
|
||||
};
|
||||
};
|
||||
|
||||
export { useDeleteDomain, type DeleteDomainParams };
|
||||
25
src/api/hooks/admin/useDomains.ts
Normal file
25
src/api/hooks/admin/useDomains.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
|
||||
import { useApi } from 'soapbox/hooks';
|
||||
import { domainSchema, type Domain } from 'soapbox/schemas';
|
||||
|
||||
const useDomains = () => {
|
||||
const api = useApi();
|
||||
|
||||
const getDomains = async () => {
|
||||
const { data } = await api.get<Domain[]>('/api/v1/pleroma/admin/domains');
|
||||
|
||||
const normalizedData = data.map((domain) => domainSchema.parse(domain));
|
||||
return normalizedData;
|
||||
};
|
||||
|
||||
const result = useQuery<ReadonlyArray<Domain>>({
|
||||
queryKey: ['domains'],
|
||||
queryFn: getDomains,
|
||||
placeholderData: [],
|
||||
});
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
export { useDomains };
|
||||
20
src/api/hooks/admin/useUpdateDomain.ts
Normal file
20
src/api/hooks/admin/useUpdateDomain.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { Entities } from 'soapbox/entity-store/entities';
|
||||
import { useCreateEntity } from 'soapbox/entity-store/hooks';
|
||||
import { useApi } from 'soapbox/hooks';
|
||||
import { domainSchema } from 'soapbox/schemas';
|
||||
|
||||
import type { CreateDomainParams } from './useCreateDomain';
|
||||
|
||||
const useUpdateDomain = (id: string) => {
|
||||
const api = useApi();
|
||||
|
||||
const { createEntity, ...rest } = useCreateEntity([Entities.DOMAINS], (params: Omit<CreateDomainParams, 'domain'>) =>
|
||||
api.patch(`/api/v1/pleroma/admin/domains/${id}`, params), { schema: domainSchema });
|
||||
|
||||
return {
|
||||
updateDomain: createEntity,
|
||||
...rest,
|
||||
};
|
||||
};
|
||||
|
||||
export { useUpdateDomain };
|
||||
Reference in New Issue
Block a user