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,39 @@
import {BackendResponse} from '@common/http/backend-response/backend-response';
import {useMutation} from '@tanstack/react-query';
import {apiClient, queryClient} from '@common/http/query-client';
import {UseFormReturn} from 'react-hook-form';
import {onFormQueryError} from '@common/errors/on-form-query-error';
import {Person} from '@app/titles/models/person';
import {toast} from '@common/ui/toast/toast';
import {message} from '@common/i18n/message';
interface Response extends BackendResponse {
person: Person;
}
export interface CreatePersonPayload {
name: string;
known_for: string;
poster: string;
birth_date: string;
death_date: string;
birth_place: string;
description: string;
gender: string;
popularity: number;
}
export function useCreatePerson(form: UseFormReturn<CreatePersonPayload>) {
return useMutation({
mutationFn: (payload: CreatePersonPayload) => createPerson(payload),
onSuccess: async () => {
await queryClient.invalidateQueries({queryKey: ['people']});
toast(message('Person created'));
},
onError: r => onFormQueryError(r, form),
});
}
function createPerson(payload: CreatePersonPayload): Promise<Response> {
return apiClient.post(`people`, payload).then(r => r.data);
}

View File

@@ -0,0 +1,42 @@
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 {toast} from '@common/ui/toast/toast';
import {message} from '@common/i18n/message';
import {titleCreditsQueryKey} from '@app/admin/titles/requests/use-title-credits';
import {PersonCredit} from '@app/titles/models/title';
import {useParams} from 'react-router-dom';
interface Response extends BackendResponse {}
export function useDeletePersonCredit(credit: PersonCredit) {
const {personId} = useParams();
return useMutation({
mutationFn: () =>
deleteCredit(credit.id, undefined, undefined, credit.pivot.id),
onSuccess: async () => {
await queryClient.invalidateQueries({
queryKey: titleCreditsQueryKey(credit.id),
});
await queryClient.invalidateQueries({
queryKey: ['people', `${personId}`],
});
toast(message('Credit deleted'));
},
onError: r => showHttpErrorToast(r),
});
}
function deleteCredit(
titleId: number | string,
season: string | undefined,
episode: string | undefined,
creditId: number | string,
): Promise<Response> {
return apiClient
.delete(`titles/${titleId}/credits/${creditId}`, {
params: {season, episode},
})
.then(r => r.data);
}

View File

@@ -0,0 +1,36 @@
import {BackendResponse} from '@common/http/backend-response/backend-response';
import {useMutation} from '@tanstack/react-query';
import {apiClient, queryClient} from '@common/http/query-client';
import {UseFormReturn} from 'react-hook-form';
import {onFormQueryError} from '@common/errors/on-form-query-error';
import {Person} from '@app/titles/models/person';
import {CreatePersonPayload} from '@app/admin/people/requests/use-create-person';
import {useParams} from 'react-router-dom';
import {toast} from '@common/ui/toast/toast';
import {message} from '@common/i18n/message';
interface Response extends BackendResponse {
person: Person;
}
export function useUpdatePerson(form: UseFormReturn<CreatePersonPayload>) {
const {personId} = useParams();
return useMutation({
mutationFn: (payload: CreatePersonPayload) =>
updatePerson(payload, personId!),
onSuccess: async () => {
await queryClient.invalidateQueries({
queryKey: ['people', `${personId}`],
});
toast(message('Person updated'));
},
onError: r => onFormQueryError(r, form),
});
}
function updatePerson(
payload: CreatePersonPayload,
personId: string,
): Promise<Response> {
return apiClient.put(`people/${personId}`, payload).then(r => r.data);
}