From d683e0c0c5e5529f64874f2530cdb1e42b7bda22 Mon Sep 17 00:00:00 2001 From: devjoaov Date: Tue, 23 Jul 2024 15:44:48 -0300 Subject: [PATCH] chore: form action can have fields --- .../DataTable/DynamicActionComponent.tsx | 49 ++++++++++++++++++- src/locales/en/translation.json | 3 +- src/locales/pt-BR/translation.json | 5 +- src/locales/pt-BR/translation_old.json | 3 ++ 4 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 src/locales/pt-BR/translation_old.json diff --git a/src/components/DataTable/DynamicActionComponent.tsx b/src/components/DataTable/DynamicActionComponent.tsx index ad9f4a4..1ac2c1a 100644 --- a/src/components/DataTable/DynamicActionComponent.tsx +++ b/src/components/DataTable/DynamicActionComponent.tsx @@ -16,7 +16,9 @@ import { AlertDialogTrigger, } from "#/components/ui/AlertDialog"; import { Button } from "#/components/ui/Button"; -import { Form } from "#/components/ui/Form"; +import { Dialog, DialogContent, DialogTrigger } from "../ui/Dialog"; +import { Form } from "../ui/Form"; +import { buildForm } from "../FormBuilder/buildForm"; export const DynamicActionComponent = ({ action, row }) => { const renderActionButton = () => { @@ -54,6 +56,7 @@ export const DynamicActionComponent = ({ action, row }) => { interface ActionFormProps { action: { + form?: any; method: string; name: string; trigger_confirmation: boolean; @@ -76,6 +79,50 @@ export const ActionForm: React.FC = ({ const [isDialogOpen, setIsDialogOpen] = React.useState(false); const [isSubmitting, setIsSubmitting] = React.useState(false); + if (action?.form?.fields) { + return ( + + + {children || ( + + )} + + +
+ + {action.name} + + + Fill in the fields to confirm the action + +
+
setIsSubmitting(true)} + action={action.url_path.replace("RESOURCE_ID", row.original.id)} + method="post" + {...form} + > +
+ {action.method === "delete" && ( + + )} +
+ {buildForm(action?.form?.fields, form)} +
+
+ + Confirm + +
+
+
+
+
+ ); + } + return ( <> {action?.trigger_confirmation && ( diff --git a/src/locales/en/translation.json b/src/locales/en/translation.json index 940f613..26e3876 100644 --- a/src/locales/en/translation.json +++ b/src/locales/en/translation.json @@ -12,10 +12,11 @@ "Search": "Search...", "View": "View", "Toggle columns": "Toggle columns", + "Fill in the fields to confirm the action": "Fill in the fields to confirm the action", + "Confirm": "Confirm", "Are you sure?": "Are you sure?", "This action cannot be undone": "This action cannot be undone.", "Cancel": "Cancel", - "Confirm": "Confirm", "Open": "Open", "Something went wrong!": "Something went wrong!", "Pick a date": "Pick a date", diff --git a/src/locales/pt-BR/translation.json b/src/locales/pt-BR/translation.json index 665da0b..c56047b 100644 --- a/src/locales/pt-BR/translation.json +++ b/src/locales/pt-BR/translation.json @@ -12,10 +12,11 @@ "Search": "Pesquise por palavra chave...", "View": "Visualizar", "Toggle columns": "Alternar colunas", + "Fill in the fields to confirm the action": "Preencha os campos para confirmar a ação", + "Confirm": "Confirmar", "Are you sure?": "Você tem certeza?", - "This action cannot be undone.": "Esta ação não pode ser desfeita.", + "This action cannot be undone": "Esta ação não pode ser desfeita.", "Cancel": "Cancelar", - "Confirm": "Confirmar", "Open": "Abrir", "Something went wrong!": "Algo deu errado!", "Pick a date": "Escolha uma data", diff --git a/src/locales/pt-BR/translation_old.json b/src/locales/pt-BR/translation_old.json new file mode 100644 index 0000000..4617054 --- /dev/null +++ b/src/locales/pt-BR/translation_old.json @@ -0,0 +1,3 @@ +{ + "This action cannot be undone.": "Esta ação não pode ser desfeita." +}