/*
* Copyright (c) 2021 - 2024, Ludvig Lundgren and the autobrr contributors.
* SPDX-License-Identifier: GPL-2.0-or-later
*/
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { APIClient } from "@api/APIClient.ts";
import { ReleaseProfileDuplicateKeys } from "@api/query_keys.ts";
import { toast } from "@components/hot-toast";
import Toast from "@components/notifications/Toast.tsx";
import { SwitchGroupWide, TextFieldWide } from "@components/inputs";
import { SlideOver } from "@components/panels";
import { AddFormProps, UpdateFormProps } from "@forms/_shared";
export function ReleaseProfileDuplicateAddForm({ isOpen, toggle }: AddFormProps) {
const queryClient = useQueryClient();
const addMutation = useMutation({
mutationFn: (profile: ReleaseProfileDuplicate) => APIClient.release.profiles.duplicates.store(profile),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ReleaseProfileDuplicateKeys.lists() });
toast.custom((t) => );
toggle();
},
onError: () => {
toast.custom((t) => );
}
});
const onSubmit = (data: unknown) => addMutation.mutate(data as ReleaseProfileDuplicate);
const initialValues: ReleaseProfileDuplicate = {
id: 0,
name: "",
protocol: false,
release_name: false,
hash: false,
title: false,
sub_title: false,
year: false,
month: false,
day: false,
source: false,
resolution: false,
codec: false,
container: false,
dynamic_range: false,
audio: false,
group: false,
season: false,
episode: false,
website: false,
proper: false,
repack: false,
edition: false,
language: false,
};
return (
{() => (
)}
);
}
export function ReleaseProfileDuplicateUpdateForm({ isOpen, toggle, data: profile }: UpdateFormProps) {
const queryClient = useQueryClient();
const storeMutation = useMutation({
mutationFn: (profile: ReleaseProfileDuplicate) => APIClient.release.profiles.duplicates.store(profile),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ReleaseProfileDuplicateKeys.lists() });
toast.custom((t) => );
toggle();
},
onError: () => {
toast.custom((t) => );
}
});
const onSubmit = (data: unknown) => storeMutation.mutate(data as ReleaseProfileDuplicate);
const deleteMutation = useMutation({
mutationFn: (profileId: number) => APIClient.release.profiles.duplicates.delete(profileId),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ReleaseProfileDuplicateKeys.lists() });
queryClient.invalidateQueries({ queryKey: ReleaseProfileDuplicateKeys.detail(profile.id) });
toast.custom((t) => );
toggle();
},
});
const onDelete = () => deleteMutation.mutate(profile.id);
const initialValues: ReleaseProfileDuplicate = {
id: profile.id,
name: profile.name,
protocol: profile.protocol,
release_name: profile.release_name,
hash: profile.hash,
title: profile.title,
sub_title: profile.sub_title,
year: profile.year,
month: profile.month,
day: profile.day,
source: profile.source,
resolution: profile.resolution,
codec: profile.codec,
container: profile.container,
dynamic_range: profile.dynamic_range,
audio: profile.audio,
group: profile.group,
season: profile.season,
episode: profile.episode,
website: profile.website,
proper: profile.proper,
repack: profile.repack,
edition: profile.edition,
language: profile.language,
};
return (
{() => (
)}
);
}