2023-05-02 10:25:32 -07:00
|
|
|
import { z } from 'zod';
|
|
|
|
|
|
|
|
import { Entities } from 'soapbox/entity-store/entities';
|
|
|
|
import { useEntity } from 'soapbox/entity-store/hooks';
|
2023-06-26 10:09:30 -07:00
|
|
|
import { useApi } from 'soapbox/hooks';
|
2023-05-02 10:25:32 -07:00
|
|
|
import { type GroupRelationship, groupRelationshipSchema } from 'soapbox/schemas';
|
|
|
|
|
2023-05-11 11:41:31 -07:00
|
|
|
function useGroupRelationship(groupId: string | undefined) {
|
2023-05-02 10:25:32 -07:00
|
|
|
const api = useApi();
|
|
|
|
|
|
|
|
const { entity: groupRelationship, ...result } = useEntity<GroupRelationship>(
|
2023-06-26 10:09:30 -07:00
|
|
|
[Entities.GROUP_RELATIONSHIPS, groupId!],
|
2023-05-02 10:25:32 -07:00
|
|
|
() => api.get(`/api/v1/groups/relationships?id[]=${groupId}`),
|
2023-05-11 11:41:31 -07:00
|
|
|
{
|
|
|
|
enabled: !!groupId,
|
2023-06-25 10:01:34 -07:00
|
|
|
schema: z.array(groupRelationshipSchema).nonempty().transform(arr => arr[0]),
|
2023-05-11 11:41:31 -07:00
|
|
|
},
|
2023-05-02 10:25:32 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
return {
|
2023-06-26 10:09:30 -07:00
|
|
|
groupRelationship,
|
2023-05-02 10:25:32 -07:00
|
|
|
...result,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export { useGroupRelationship };
|