Files
ncd-fe/src/api/hooks/groups/useCreateGroup.ts
marcin mikołajczak 32c68a9221 Migrate to external library for interacting with API
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
2024-08-06 19:52:36 +02:00

33 lines
848 B
TypeScript

import { serialize } from 'object-to-formdata';
import { Entities } from 'soapbox/entity-store/entities';
import { useCreateEntity } from 'soapbox/entity-store/hooks';
import { useClient } from 'soapbox/hooks';
import { groupSchema } from 'soapbox/schemas';
interface CreateGroupParams {
display_name?: string;
note?: string;
avatar?: File;
header?: File;
group_visibility?: 'members_only' | 'everyone';
discoverable?: boolean;
tags?: string[];
}
const useCreateGroup = () => {
const client = useClient();
const { createEntity, ...rest } = useCreateEntity(
[Entities.GROUPS, 'search', ''],
(params: CreateGroupParams) => client.experimental.groups.createGroup(params),
{ schema: groupSchema },
);
return {
createGroup: createEntity,
...rest,
};
};
export { useCreateGroup, type CreateGroupParams };