33
resources/client/admin/titles/requests/use-create-season.ts
Executable file
33
resources/client/admin/titles/requests/use-create-season.ts
Executable file
@@ -0,0 +1,33 @@
|
||||
import {BackendResponse} from '@common/http/backend-response/backend-response';
|
||||
import {useMutation} from '@tanstack/react-query';
|
||||
import {apiClient, queryClient} from '@common/http/query-client';
|
||||
import {showHttpErrorToast} from '@common/utils/http/show-http-error-toast';
|
||||
import {titleSeasonsQueryKey} from '@app/titles/requests/use-title-seasons';
|
||||
import {toast} from '@common/ui/toast/toast';
|
||||
import {message} from '@common/i18n/message';
|
||||
import {Season} from '@app/titles/models/season';
|
||||
|
||||
interface Response extends BackendResponse {
|
||||
season: Season;
|
||||
}
|
||||
|
||||
export function useCreateSeason(titleId: number) {
|
||||
return useMutation({
|
||||
mutationFn: () => createSeason(titleId),
|
||||
onSuccess: async response => {
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: titleSeasonsQueryKey(response.season.title_id),
|
||||
});
|
||||
toast(
|
||||
message('Season :number created', {
|
||||
values: {number: response.season.number},
|
||||
}),
|
||||
);
|
||||
},
|
||||
onError: r => showHttpErrorToast(r),
|
||||
});
|
||||
}
|
||||
|
||||
function createSeason(titleId: number): Promise<Response> {
|
||||
return apiClient.post(`titles/${titleId}/seasons`).then(r => r.data);
|
||||
}
|
||||
Reference in New Issue
Block a user