first commit
Some checks failed
Build / run (push) Has been cancelled

This commit is contained in:
maher
2025-10-29 11:42:25 +01:00
commit 703f50a09d
4595 changed files with 385164 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
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 {UseFormReturn} from 'react-hook-form';
import {onFormQueryError} from '@common/errors/on-form-query-error';
import {seasonQueryKey} from '@app/seasons/requests/use-season';
import {Episode} from '@app/titles/models/episode';
interface Response extends BackendResponse {
episode: Episode;
}
export interface CreateEpisodePayload {
name: string;
description: string;
release_date: string;
runtime: number;
popularity: number;
poster: string;
}
export function useCreateEpisode(
form: UseFormReturn<CreateEpisodePayload>,
titleId: number,
season: number | string,
) {
return useMutation({
mutationFn: (payload: CreateEpisodePayload) =>
createEpisode(titleId, season, payload),
onSuccess: async () => {
await queryClient.invalidateQueries({
queryKey: seasonQueryKey(titleId, season),
});
},
onError: r => (form ? onFormQueryError(r, form) : showHttpErrorToast(r)),
});
}
function createEpisode(
titleId: number,
season: number | string,
payload: CreateEpisodePayload,
): Promise<Response> {
return apiClient
.post(`titles/${titleId}/seasons/${season}/episodes`, payload)
.then(r => r.data);
}