feat: enhance FormServizio and FormServizioAcquisto with new button styles and functionality
This commit is contained in:
parent
f0ba2afcb2
commit
0c89a62c55
3 changed files with 40 additions and 14 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { createContext, type ReactNode, useContext } from "react";
|
import type { DialogContentProps } from "@radix-ui/react-dialog";
|
||||||
|
import { createContext, type ReactNode, type RefAttributes, useContext } from "react";
|
||||||
import type { Drawer as DrawerPrimitive } from "vaul";
|
import type { Drawer as DrawerPrimitive } from "vaul";
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
|
|
@ -148,7 +149,7 @@ const CredenzaClose = ({ className, children, ...props }: CredenzaProps) => {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const CredenzaContent = ({ className, children, ...props }: CredenzaProps) => {
|
const CredenzaContent = ({ className, children, ...props }: DialogContentProps & RefAttributes<HTMLDivElement> ) => {
|
||||||
const { isDesktop } = useCredenzaContext();
|
const { isDesktop } = useCredenzaContext();
|
||||||
const CredenzaContent = isDesktop ? DialogContent : DrawerContent;
|
const CredenzaContent = isDesktop ? DialogContent : DrawerContent;
|
||||||
|
|
||||||
|
|
@ -217,13 +218,13 @@ const CredenzaFooter = ({ className, children, ...props }: CredenzaProps) => {
|
||||||
|
|
||||||
export {
|
export {
|
||||||
Credenza,
|
Credenza,
|
||||||
//CredenzaNested,
|
CredenzaBody,
|
||||||
CredenzaTrigger,
|
|
||||||
CredenzaClose,
|
CredenzaClose,
|
||||||
CredenzaContent,
|
CredenzaContent,
|
||||||
CredenzaDescription,
|
CredenzaDescription,
|
||||||
|
CredenzaFooter,
|
||||||
CredenzaHeader,
|
CredenzaHeader,
|
||||||
CredenzaTitle,
|
CredenzaTitle,
|
||||||
CredenzaBody,
|
//CredenzaNested,
|
||||||
CredenzaFooter,
|
CredenzaTrigger,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { format } from "date-fns";
|
import { format } from "date-fns";
|
||||||
import { it } from "date-fns/locale";
|
import { it } from "date-fns/locale";
|
||||||
import { CalendarIcon, SlidersHorizontal } from "lucide-react";
|
import { CalendarIcon, Check, SlidersHorizontal } from "lucide-react";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import toast from "react-hot-toast";
|
import toast from "react-hot-toast";
|
||||||
import { z } from "zod/v4";
|
import { z } from "zod/v4";
|
||||||
|
|
@ -96,10 +96,12 @@ const FormServizio = ({
|
||||||
initialData,
|
initialData,
|
||||||
onSubmit,
|
onSubmit,
|
||||||
isLimited,
|
isLimited,
|
||||||
|
setOpen,
|
||||||
}: {
|
}: {
|
||||||
initialData: Servizio | undefined;
|
initialData: Servizio | undefined;
|
||||||
onSubmit: (fields: FormValues) => void;
|
onSubmit: (fields: FormValues) => void;
|
||||||
isLimited: boolean;
|
isLimited: boolean;
|
||||||
|
setOpen?: (open: boolean) => void;
|
||||||
}) => {
|
}) => {
|
||||||
// This can come from your database or API.
|
// This can come from your database or API.
|
||||||
let defaultValues: FormValues;
|
let defaultValues: FormValues;
|
||||||
|
|
@ -245,7 +247,7 @@ const FormServizio = ({
|
||||||
</FormItem>
|
</FormItem>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
<div className="flex w-full items-start justify-between gap-x-4">
|
<div className="grid w-full grid-cols-1 items-start gap-4 sm:grid-cols-2">
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="entromese"
|
name="entromese"
|
||||||
|
|
@ -627,8 +629,9 @@ const FormServizio = ({
|
||||||
if (isLimited) return;
|
if (isLimited) return;
|
||||||
field.onChange(!field.value);
|
field.onChange(!field.value);
|
||||||
}}
|
}}
|
||||||
variant={field.value ? "default" : "secondary"}
|
variant={field.value ? "default" : "outline"}
|
||||||
>
|
>
|
||||||
|
{field.value && <Check />}
|
||||||
{pair[1]}
|
{pair[1]}
|
||||||
</Badge>
|
</Badge>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
|
|
@ -724,7 +727,22 @@ const FormServizio = ({
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)} */}
|
)} */}
|
||||||
{!isLimited && <Button type="submit">Salva</Button>}
|
<div className="flex w-full justify-end gap-2">
|
||||||
|
{!isLimited && (
|
||||||
|
<Button type="submit" variant="success">
|
||||||
|
Salva
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<Button
|
||||||
|
disabled={isLimited || form.formState.isDirty}
|
||||||
|
onClick={() => setOpen?.(false)}
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
>
|
||||||
|
Chiudi
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</Form>
|
</Form>
|
||||||
);
|
);
|
||||||
|
|
@ -822,18 +840,24 @@ export const EditServizioModal = () => {
|
||||||
{t.servizio.parametri.btn}
|
{t.servizio.parametri.btn}
|
||||||
</Button>
|
</Button>
|
||||||
</CredenzaTrigger>
|
</CredenzaTrigger>
|
||||||
<CredenzaContent className="max-h-[90vh] w-full sm:max-w-5xl">
|
<CredenzaContent
|
||||||
|
className="max-h-[90vh] w-full **:data-[slot=dialog-close]:hidden sm:max-w-5xl"
|
||||||
|
onInteractOutside={(e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
}}
|
||||||
|
>
|
||||||
<CredenzaHeader>
|
<CredenzaHeader>
|
||||||
<CredenzaTitle>{t.servizio.parametri.title}</CredenzaTitle>
|
<CredenzaTitle>{t.servizio.parametri.title}</CredenzaTitle>
|
||||||
<CredenzaDescription className="sr-only">
|
<CredenzaDescription className="sr-only">
|
||||||
{t.servizio.parametri.title}
|
{t.servizio.parametri.title}
|
||||||
</CredenzaDescription>
|
</CredenzaDescription>
|
||||||
</CredenzaHeader>
|
</CredenzaHeader>
|
||||||
<CredenzaBody className="max-h-[80vh] w-full max-w-3xl overflow-y-auto pb-5 sm:max-w-5xl">
|
<CredenzaBody className="w-full max-w-3xl overflow-y-auto pb-5 sm:max-w-5xl">
|
||||||
<FormServizio
|
<FormServizio
|
||||||
initialData={servizio}
|
initialData={servizio}
|
||||||
isLimited={!isAdmin}
|
isLimited={!isAdmin}
|
||||||
onSubmit={onSubmit}
|
onSubmit={onSubmit}
|
||||||
|
setOpen={setOpenEditParametri}
|
||||||
/>
|
/>
|
||||||
</CredenzaBody>
|
</CredenzaBody>
|
||||||
</CredenzaContent>
|
</CredenzaContent>
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
"use client";
|
"use client";
|
||||||
import { format } from "date-fns";
|
import { format } from "date-fns";
|
||||||
import { enUS, it } from "date-fns/locale";
|
import { enUS, it } from "date-fns/locale";
|
||||||
import { CalendarIcon, HelpCircleIcon, Mail } from "lucide-react";
|
import { CalendarIcon, Check, HelpCircleIcon, Mail } from "lucide-react";
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
import { type Control, useWatch } from "react-hook-form";
|
import { type Control, useWatch } from "react-hook-form";
|
||||||
import toast from "react-hot-toast";
|
import toast from "react-hot-toast";
|
||||||
|
|
@ -834,8 +834,9 @@ export const FormServizioAcquisto = ({
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
field.onChange(!field.value);
|
field.onChange(!field.value);
|
||||||
}}
|
}}
|
||||||
variant={field.value ? "default" : "secondary"}
|
variant={field.value ? "default" : "outline"}
|
||||||
>
|
>
|
||||||
|
{field.value && <Check />}
|
||||||
{pair[1]}
|
{pair[1]}
|
||||||
</Badge>
|
</Badge>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue