feat: update Counter component to conditionally apply disabled styles and enhance FormServizio with improved disabled state handling
This commit is contained in:
parent
cfc72a09e8
commit
ed93eb12a1
4 changed files with 44 additions and 19 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
import { Minus, Plus } from "lucide-react";
|
import { Minus, Plus } from "lucide-react";
|
||||||
import Input from "~/components/ui/input";
|
import Input from "~/components/ui/input";
|
||||||
|
import { cn } from "~/lib/utils";
|
||||||
export const Counter = ({
|
export const Counter = ({
|
||||||
value,
|
value,
|
||||||
setValue,
|
setValue,
|
||||||
|
|
@ -26,7 +27,10 @@ export const Counter = ({
|
||||||
|
|
||||||
<div className="flex items-center rounded-md border px-1">
|
<div className="flex items-center rounded-md border px-1">
|
||||||
<button
|
<button
|
||||||
className="flex size-10 cursor-pointer items-center justify-center leading-10 transition hover:opacity-75 disabled:opacity-50"
|
className={cn(
|
||||||
|
"flex size-10 cursor-pointer items-center justify-center leading-10 transition hover:opacity-75 disabled:opacity-50",
|
||||||
|
disabled && "cursor-default",
|
||||||
|
)}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
onClick={() => handleChange(-1)}
|
onClick={() => handleChange(-1)}
|
||||||
type="button"
|
type="button"
|
||||||
|
|
@ -50,7 +54,10 @@ export const Counter = ({
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
className="flex size-10 cursor-pointer items-center justify-center leading-10 transition hover:opacity-75 disabled:opacity-50"
|
className={cn(
|
||||||
|
"flex size-10 cursor-pointer items-center justify-center leading-10 transition hover:opacity-75 disabled:opacity-50",
|
||||||
|
disabled && "cursor-default",
|
||||||
|
)}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
onClick={() => handleChange(1)}
|
onClick={() => handleChange(1)}
|
||||||
type="button"
|
type="button"
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { add, addBusinessDays, isBefore } from "date-fns";
|
import { add, isBefore } from "date-fns";
|
||||||
import {
|
import {
|
||||||
Bug,
|
Bug,
|
||||||
ChevronDown,
|
ChevronDown,
|
||||||
|
|
@ -699,6 +699,7 @@ const EditParametri = () => {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const EditServizioAdmin = () => {
|
const EditServizioAdmin = () => {
|
||||||
const { servizioId, userId, servizio } = useServizio();
|
const { servizioId, userId, servizio } = useServizio();
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,6 @@ import {
|
||||||
PopoverContent,
|
PopoverContent,
|
||||||
PopoverTrigger,
|
PopoverTrigger,
|
||||||
} from "~/components/ui/popover";
|
} from "~/components/ui/popover";
|
||||||
import { Separator } from "~/components/ui/separator";
|
|
||||||
import { Slider } from "~/components/ui/slider";
|
import { Slider } from "~/components/ui/slider";
|
||||||
import { Switch } from "~/components/ui/switch";
|
import { Switch } from "~/components/ui/switch";
|
||||||
import { cn } from "~/lib/utils";
|
import { cn } from "~/lib/utils";
|
||||||
|
|
@ -202,6 +201,7 @@ export const FormServizio = ({
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<Slider
|
<Slider
|
||||||
defaultValue={[field.value]}
|
defaultValue={[field.value]}
|
||||||
|
disabled={isLimited}
|
||||||
id="budgetslider"
|
id="budgetslider"
|
||||||
max={2000}
|
max={2000}
|
||||||
min={0}
|
min={0}
|
||||||
|
|
@ -212,7 +212,9 @@ export const FormServizio = ({
|
||||||
value={[form.getValues("budget")]}
|
value={[form.getValues("budget")]}
|
||||||
/>
|
/>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
|
{!isLimited && (
|
||||||
<FormDescription>{t.parametri.budget_desc}</FormDescription>
|
<FormDescription>{t.parametri.budget_desc}</FormDescription>
|
||||||
|
)}
|
||||||
</FormItem>
|
</FormItem>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|
@ -245,6 +247,7 @@ export const FormServizio = ({
|
||||||
}
|
}
|
||||||
: undefined
|
: undefined
|
||||||
}
|
}
|
||||||
|
disabled={isLimited}
|
||||||
elementId="select-mesi"
|
elementId="select-mesi"
|
||||||
elementName="entro_mese"
|
elementName="entro_mese"
|
||||||
isMulti={false}
|
isMulti={false}
|
||||||
|
|
@ -297,7 +300,10 @@ export const FormServizio = ({
|
||||||
}
|
}
|
||||||
: undefined
|
: undefined
|
||||||
}
|
}
|
||||||
disabled={tipologia !== TipologiaPosizioneEnum.Transitorio}
|
disabled={
|
||||||
|
isLimited ||
|
||||||
|
tipologia !== TipologiaPosizioneEnum.Transitorio
|
||||||
|
}
|
||||||
elementId="permanenza"
|
elementId="permanenza"
|
||||||
elementName="permanenza"
|
elementName="permanenza"
|
||||||
isMulti={false}
|
isMulti={false}
|
||||||
|
|
@ -313,7 +319,8 @@ export const FormServizio = ({
|
||||||
placeholder="Seleziona..."
|
placeholder="Seleziona..."
|
||||||
/>
|
/>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
{tipologia === TipologiaPosizioneEnum.Transitorio && (
|
{tipologia === TipologiaPosizioneEnum.Transitorio &&
|
||||||
|
!isLimited && (
|
||||||
<FormDescription>
|
<FormDescription>
|
||||||
{t.parametri.permanenza_desc}
|
{t.parametri.permanenza_desc}
|
||||||
</FormDescription>
|
</FormDescription>
|
||||||
|
|
@ -339,6 +346,7 @@ export const FormServizio = ({
|
||||||
</div>
|
</div>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<Counter
|
<Counter
|
||||||
|
disabled={isLimited}
|
||||||
name="n_adulti"
|
name="n_adulti"
|
||||||
onlyPositive
|
onlyPositive
|
||||||
setValue={(value) => field.onChange(Number(value))}
|
setValue={(value) => field.onChange(Number(value))}
|
||||||
|
|
@ -364,6 +372,7 @@ export const FormServizio = ({
|
||||||
</div>
|
</div>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<Counter
|
<Counter
|
||||||
|
disabled={isLimited}
|
||||||
name="n_minori"
|
name="n_minori"
|
||||||
onlyPositive
|
onlyPositive
|
||||||
setValue={(value) => field.onChange(Number(value))}
|
setValue={(value) => field.onChange(Number(value))}
|
||||||
|
|
@ -387,6 +396,7 @@ export const FormServizio = ({
|
||||||
<Switch
|
<Switch
|
||||||
className="data-[state=checked]:bg-neutral-700"
|
className="data-[state=checked]:bg-neutral-700"
|
||||||
defaultChecked={field.value}
|
defaultChecked={field.value}
|
||||||
|
disabled={isLimited}
|
||||||
id="arredato"
|
id="arredato"
|
||||||
onCheckedChange={field.onChange}
|
onCheckedChange={field.onChange}
|
||||||
/>
|
/>
|
||||||
|
|
@ -546,6 +556,7 @@ export const FormServizio = ({
|
||||||
|
|
||||||
<MultiSelect
|
<MultiSelect
|
||||||
defaultValue={undefined}
|
defaultValue={undefined}
|
||||||
|
disabled={isLimited}
|
||||||
elementId="select-reddito"
|
elementId="select-reddito"
|
||||||
elementName="reddito"
|
elementName="reddito"
|
||||||
isMulti={false}
|
isMulti={false}
|
||||||
|
|
@ -566,7 +577,9 @@ export const FormServizio = ({
|
||||||
<Label htmlFor="altrePrefDialogButton">
|
<Label htmlFor="altrePrefDialogButton">
|
||||||
{t.parametri.altriparams_label}
|
{t.parametri.altriparams_label}
|
||||||
</Label>
|
</Label>
|
||||||
|
{!isLimited && (
|
||||||
<FormDescription>{t.parametri.altriparams_desc}</FormDescription>
|
<FormDescription>{t.parametri.altriparams_desc}</FormDescription>
|
||||||
|
)}
|
||||||
<div className="mt-2 flex flex-wrap gap-2">
|
<div className="mt-2 flex flex-wrap gap-2">
|
||||||
{altrePrefMapping.map((pair) => {
|
{altrePrefMapping.map((pair) => {
|
||||||
if (pair) {
|
if (pair) {
|
||||||
|
|
@ -579,8 +592,12 @@ export const FormServizio = ({
|
||||||
<FormItem>
|
<FormItem>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<Badge
|
<Badge
|
||||||
className={cn("cursor-pointer text-sm")}
|
className={cn(
|
||||||
|
"text-sm",
|
||||||
|
isLimited ? "cursor-default" : "cursor-pointer",
|
||||||
|
)}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
|
if (isLimited) return;
|
||||||
field.onChange(!field.value);
|
field.onChange(!field.value);
|
||||||
}}
|
}}
|
||||||
variant={field.value ? "default" : "secondary"}
|
variant={field.value ? "default" : "secondary"}
|
||||||
|
|
@ -596,6 +613,7 @@ export const FormServizio = ({
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{/*
|
||||||
<Separator />
|
<Separator />
|
||||||
{!isLimited && (
|
{!isLimited && (
|
||||||
<div className="flex w-full flex-col items-start justify-between gap-4 sm:flex-row">
|
<div className="flex w-full flex-col items-start justify-between gap-4 sm:flex-row">
|
||||||
|
|
@ -677,9 +695,8 @@ export const FormServizio = ({
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)} */}
|
||||||
|
{!isLimited && <Button type="submit">Salva</Button>}
|
||||||
<Button type="submit">Salva</Button>
|
|
||||||
</form>
|
</form>
|
||||||
</Form>
|
</Form>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ export const addServizio = async (data: NewServizio) => {
|
||||||
type: OrderTypeEnum.Acconto,
|
type: OrderTypeEnum.Acconto,
|
||||||
amount_cent: acconto.prezzo_cent,
|
amount_cent: acconto.prezzo_cent,
|
||||||
packid: acconto.idprezziario,
|
packid: acconto.idprezziario,
|
||||||
isActive: data.skipPayment || false,
|
isActive: false,
|
||||||
})
|
})
|
||||||
.execute();
|
.execute();
|
||||||
return servizio;
|
return servizio;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue