-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
70 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,63 @@ | ||
import { TextInput } from "@mantine/core"; | ||
import { UserContentFileElement } from "@/types"; | ||
import { Button, TextInput } from "@mantine/core"; | ||
import { useForm } from "@mantine/form"; | ||
import { useMutation, useQueryClient } from "@tanstack/react-query"; | ||
|
||
const FileEditor = () => { | ||
const form = useForm(); | ||
const FileEditor = ({ element }: { | ||
element: UserContentFileElement | ||
}) => { | ||
const queryClient = useQueryClient(); | ||
|
||
const updateFileMutation = useMutation({ | ||
mutationFn: (values) => fetch(`https://pandadiestro.xyz/services/stiller/file`, { | ||
method: 'PATCH', | ||
body: JSON.stringify(values) | ||
}), | ||
onSuccess: () => { | ||
queryClient.invalidateQueries({ queryKey: ['user/media'] }) | ||
} | ||
}); | ||
|
||
const form = useForm({ | ||
initialValues: { | ||
title: element.title, | ||
description: element.description | ||
} | ||
}); | ||
|
||
const handleSubmit = form.onSubmit(async (values) => { | ||
await updateFileMutation.mutateAsync({ ...values, id: element.id } as any); | ||
}); | ||
|
||
return ( | ||
<form> | ||
<div className="stack gap-sm"> | ||
<TextInput | ||
label="Título" | ||
placeholder="Título de la obra" | ||
/> | ||
<form onSubmit={handleSubmit}> | ||
<div className="stack gap-lg"> | ||
<div className="stack gap-sm"> | ||
<TextInput | ||
label="Título" | ||
placeholder="Título de la obra" | ||
required | ||
{...form.getInputProps('title')} | ||
key={form.key('title')} | ||
/> | ||
<TextInput | ||
label="Descripción" | ||
placeholder="Descripción de la obra" | ||
{...form.getInputProps('description')} | ||
key={form.key('description')} | ||
/> | ||
</div> | ||
<Button | ||
type="submit" | ||
variant="primary" | ||
disabled={!form.isDirty()} | ||
bg={form.isDirty() ? 'black' : 'gray.7'} | ||
> | ||
Actualizar | ||
</Button> | ||
</div> | ||
</form> | ||
) | ||
}; | ||
|
||
export default FileEditor; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import FileEditor from "./FileEditor"; | ||
|
||
export default FileEditor; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters