import { Group, Stack } from '@mantine/core'; import { useForm } from '@mantine/form'; import { ServerType, UpdatePlaylistBody, UpdatePlaylistQuery, User } from '/@/renderer/api/types'; import { Button, Select, Switch, TextInput, toast } from '/@/renderer/components'; import { useUpdatePlaylist } from '/@/renderer/features/playlists/mutations/update-playlist-mutation'; import { useCurrentServer } from '/@/renderer/store'; interface UpdatePlaylistFormProps { body: Partial; onCancel: () => void; query: UpdatePlaylistQuery; users?: User[]; } export const UpdatePlaylistForm = ({ users, query, body, onCancel }: UpdatePlaylistFormProps) => { const mutation = useUpdatePlaylist(); const server = useCurrentServer(); const userList = users?.map((user) => ({ label: user.name, value: user.id, })); const form = useForm({ initialValues: { comment: body?.comment || '', name: body?.name || '', ndParams: { owner: body?.ndParams?.owner || '', ownerId: body?.ndParams?.ownerId || '', public: body?.ndParams?.public || false, rules: undefined, sync: body?.ndParams?.sync || false, }, }, }); const handleSubmit = form.onSubmit((values) => { mutation.mutate( { body: values, query }, { onError: (err) => { toast.error({ message: err.message, title: 'Error updating playlist' }); }, onSuccess: () => { toast.success({ message: `Playlist has been saved` }); onCancel(); }, }, ); }); const isPublicDisplayed = server?.type === ServerType.NAVIDROME; const isSubmitDisabled = !form.values.name || mutation.isLoading; return (