Replace axios with fetch
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
@@ -10,7 +10,7 @@ function useCancelMembershipRequest(group: Group) {
|
||||
|
||||
const { createEntity, isSubmitting } = useCreateEntity(
|
||||
[Entities.GROUP_RELATIONSHIPS],
|
||||
() => api.post(`/api/v1/groups/${group.id}/membership_requests/${me?.id}/reject`),
|
||||
() => api(`/api/v1/groups/${group.id}/membership_requests/${me?.id}/reject`, { method: 'POST' }),
|
||||
);
|
||||
|
||||
return {
|
||||
|
||||
@@ -17,10 +17,16 @@ function useCreateGroup() {
|
||||
const api = useApi();
|
||||
|
||||
const { createEntity, ...rest } = useCreateEntity([Entities.GROUPS, 'search', ''], (params: CreateGroupParams) => {
|
||||
return api.post('/api/v1/groups', params, {
|
||||
const formData = new FormData();
|
||||
|
||||
Object.entries(params).forEach(([key, value]) => formData.append(key, value));
|
||||
|
||||
return api('/api/v1/groups', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data',
|
||||
},
|
||||
body: formData,
|
||||
});
|
||||
}, { schema: groupSchema });
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ function useDeleteGroupStatus(group: Group, statusId: string) {
|
||||
const api = useApi();
|
||||
const { deleteEntity, isSubmitting } = useDeleteEntity(
|
||||
Entities.STATUSES,
|
||||
() => api.delete(`/api/v1/groups/${group.id}/statuses/${statusId}`),
|
||||
() => api(`/api/v1/groups/${group.id}/statuses/${statusId}`, { method: 'DELETE' }),
|
||||
);
|
||||
|
||||
return {
|
||||
|
||||
@@ -14,7 +14,7 @@ function useGroup(groupId: string, refetch = true) {
|
||||
|
||||
const { entity: group, isUnauthorized, ...result } = useEntity<Group>(
|
||||
[Entities.GROUPS, groupId],
|
||||
() => api.get(`/api/v1/groups/${groupId}`),
|
||||
() => api(`/api/v1/groups/${groupId}`),
|
||||
{
|
||||
schema: groupSchema,
|
||||
refetch,
|
||||
|
||||
@@ -10,7 +10,7 @@ function useGroupMedia(groupId: string) {
|
||||
const api = useApi();
|
||||
|
||||
return useEntities([Entities.STATUSES, 'groupMedia', groupId], () => {
|
||||
return api.get(`/api/v1/timelines/group/${groupId}?only_media=true`);
|
||||
return api(`/api/v1/timelines/group/${groupId}?only_media=true`);
|
||||
}, { schema: statusSchema });
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ function useGroupMembers(groupId: string, role: GroupRoles) {
|
||||
|
||||
const { entities, ...result } = useEntities<GroupMember>(
|
||||
[Entities.GROUP_MEMBERSHIPS, groupId, role],
|
||||
() => api.get(`/api/v1/groups/${groupId}/memberships?role=${role}`),
|
||||
() => api(`/api/v1/groups/${groupId}/memberships?role=${role}`),
|
||||
{ schema: groupMemberSchema },
|
||||
);
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ function useGroupMembershipRequests(groupId: string) {
|
||||
|
||||
const { entities, invalidate, fetchEntities, ...rest } = useEntities(
|
||||
path,
|
||||
() => api.get(`/api/v1/groups/${groupId}/membership_requests`),
|
||||
() => api(`/api/v1/groups/${groupId}/membership_requests`),
|
||||
{
|
||||
schema: accountSchema,
|
||||
enabled: relationship?.role === GroupRoles.OWNER || relationship?.role === GroupRoles.ADMIN,
|
||||
@@ -24,13 +24,13 @@ function useGroupMembershipRequests(groupId: string) {
|
||||
);
|
||||
|
||||
const { dismissEntity: authorize } = useDismissEntity(path, async (accountId: string) => {
|
||||
const response = await api.post(`/api/v1/groups/${groupId}/membership_requests/${accountId}/authorize`);
|
||||
const response = await api(`/api/v1/groups/${groupId}/membership_requests/${accountId}/authorize`, { method: 'POST' });
|
||||
invalidate();
|
||||
return response;
|
||||
});
|
||||
|
||||
const { dismissEntity: reject } = useDismissEntity(path, async (accountId: string) => {
|
||||
const response = await api.post(`/api/v1/groups/${groupId}/membership_requests/${accountId}/reject`);
|
||||
const response = await api(`/api/v1/groups/${groupId}/membership_requests/${accountId}/reject`, { method: 'POST' });
|
||||
invalidate();
|
||||
return response;
|
||||
});
|
||||
|
||||
@@ -10,7 +10,7 @@ function useGroupRelationship(groupId: string | undefined) {
|
||||
|
||||
const { entity: groupRelationship, ...result } = useEntity<GroupRelationship>(
|
||||
[Entities.GROUP_RELATIONSHIPS, groupId!],
|
||||
() => api.get(`/api/v1/groups/relationships?id[]=${groupId}`),
|
||||
() => api(`/api/v1/groups/relationships?id[]=${groupId}`),
|
||||
{
|
||||
enabled: !!groupId,
|
||||
schema: z.array(groupRelationshipSchema).nonempty().transform(arr => arr[0]),
|
||||
|
||||
@@ -8,8 +8,7 @@ function useGroupRelationships(listKey: string[], ids: string[]) {
|
||||
const { isLoggedIn } = useLoggedIn();
|
||||
|
||||
function fetchGroupRelationships(ids: string[]) {
|
||||
const q = ids.map((id) => `id[]=${id}`).join('&');
|
||||
return api.get(`/api/v1/groups/relationships?${q}`);
|
||||
return api('/api/v1/groups/relationships', { params: { ids } });
|
||||
}
|
||||
|
||||
const { entityMap: relationships, ...result } = useBatchedEntities<GroupRelationship>(
|
||||
|
||||
@@ -12,7 +12,7 @@ function useGroups() {
|
||||
|
||||
const { entities, ...result } = useEntities<Group>(
|
||||
[Entities.GROUPS, 'search', ''],
|
||||
() => api.get('/api/v1/groups'),
|
||||
() => api('/api/v1/groups'),
|
||||
{ enabled: features.groups, schema: groupSchema },
|
||||
);
|
||||
const { relationships } = useGroupRelationships(
|
||||
|
||||
@@ -16,10 +16,16 @@ function useUpdateGroup(groupId: string) {
|
||||
const api = useApi();
|
||||
|
||||
const { createEntity, ...rest } = useCreateEntity([Entities.GROUPS], (params: UpdateGroupParams) => {
|
||||
return api.put(`/api/v1/groups/${groupId}`, params, {
|
||||
const formData = new FormData();
|
||||
|
||||
Object.entries(params).forEach(([key, value]) => formData.append(key, value));
|
||||
|
||||
return api(`/api/v1/groups/${groupId}`, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data',
|
||||
},
|
||||
body: formData,
|
||||
});
|
||||
}, { schema: groupSchema });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user