fix modal filter
This commit is contained in:
@@ -1,19 +1,16 @@
|
||||
'use client';
|
||||
|
||||
import React, { useState, useEffect, useMemo } from "react";
|
||||
import React, { useState, useEffect } from "react";
|
||||
import Button from "@/components/button/PrimaryButton";
|
||||
import AnimatedBottomSheet from "@/components/bottomsheet/AnimatedBottomSheet";
|
||||
import ComboBox, { ComboboxOption } from "@/components/combobox/Combobox";
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
import { TicketPercentIcon } from "lucide-react";
|
||||
|
||||
type MenuFilterDrawerProps = {
|
||||
visible: boolean;
|
||||
onClose: () => void;
|
||||
selectedIngredients: string;
|
||||
selectedDeliveryId: string;
|
||||
onIngredientsChange: (value: string) => void;
|
||||
onDeliveryChange: (value: string) => void;
|
||||
searchQuery: string;
|
||||
onSearchChange: (value: string) => void;
|
||||
onApply: () => void;
|
||||
tMenu: (key: string) => string;
|
||||
};
|
||||
@@ -21,67 +18,31 @@ type MenuFilterDrawerProps = {
|
||||
const MenuFilterDrawer = ({
|
||||
visible,
|
||||
onClose,
|
||||
selectedIngredients,
|
||||
selectedDeliveryId,
|
||||
onIngredientsChange,
|
||||
onDeliveryChange,
|
||||
searchQuery,
|
||||
onSearchChange,
|
||||
onApply,
|
||||
tMenu,
|
||||
}: MenuFilterDrawerProps) => {
|
||||
const [tempIngredients, setTempIngredients] = useState(selectedIngredients);
|
||||
const [tempDeliveryId, setTempDeliveryId] = useState(selectedDeliveryId);
|
||||
const [tempQuery, setTempQuery] = useState(searchQuery);
|
||||
|
||||
useEffect(() => {
|
||||
if (visible) {
|
||||
setTempIngredients(selectedIngredients);
|
||||
setTempDeliveryId(selectedDeliveryId);
|
||||
setTempQuery(searchQuery);
|
||||
}
|
||||
}, [visible, selectedIngredients, selectedDeliveryId]);
|
||||
}, [visible, searchQuery]);
|
||||
|
||||
const serviceOptions: Array<ComboboxOption> = useMemo(() => {
|
||||
return [
|
||||
{
|
||||
id: "0",
|
||||
title: tMenu("MenuFilterDrawer.SelectDelivery.Options.All") || "همه",
|
||||
label: "",
|
||||
},
|
||||
{
|
||||
id: "pickup",
|
||||
title: "بیرون بر",
|
||||
label: "",
|
||||
},
|
||||
{
|
||||
id: "inPlace",
|
||||
title: "سرو در فروشگاه",
|
||||
label: "",
|
||||
},
|
||||
];
|
||||
}, [tMenu]);
|
||||
|
||||
const handleIngredientsChange = (
|
||||
e: React.ChangeEvent<HTMLInputElement>
|
||||
) => {
|
||||
setTempIngredients(e.target.value);
|
||||
};
|
||||
|
||||
const handleDeliveryChange = (
|
||||
e: React.MouseEvent<HTMLDivElement, MouseEvent>,
|
||||
index: number
|
||||
) => {
|
||||
e.stopPropagation();
|
||||
setTempDeliveryId(serviceOptions[index]?.id ?? serviceOptions[0].id);
|
||||
const handleSearchChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
setTempQuery(e.target.value);
|
||||
};
|
||||
|
||||
const handleApply = () => {
|
||||
onIngredientsChange(tempIngredients);
|
||||
onDeliveryChange(tempDeliveryId);
|
||||
onSearchChange(tempQuery);
|
||||
onApply();
|
||||
onClose();
|
||||
};
|
||||
|
||||
const handleCancel = () => {
|
||||
setTempIngredients(selectedIngredients);
|
||||
setTempDeliveryId(selectedDeliveryId);
|
||||
setTempQuery(searchQuery);
|
||||
onClose();
|
||||
};
|
||||
|
||||
@@ -99,19 +60,12 @@ const MenuFilterDrawer = ({
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
value={tempIngredients}
|
||||
onChange={handleIngredientsChange}
|
||||
placeholder={tMenu("MenuFilterDrawer.SelectContent.Placeholder") || "محتویات را وارد کنید..."}
|
||||
value={tempQuery}
|
||||
onChange={handleSearchChange}
|
||||
placeholder={tMenu("MenuFilterDrawer.SelectContent.Placeholder")}
|
||||
className="w-full h-11 px-3 py-2.5 rounded-normal border border-border bg-container/29 focus:outline-none focus:ring-2 focus:ring-black text-xs!"
|
||||
/>
|
||||
</div>
|
||||
<ComboBox
|
||||
className="relative mt-9.5"
|
||||
title={tMenu("MenuFilterDrawer.SelectDelivery.Label")}
|
||||
options={serviceOptions}
|
||||
selectedId={tempDeliveryId}
|
||||
onSelectionChange={handleDeliveryChange}
|
||||
/>
|
||||
<div className="flex w-full mt-[23px] h-11 items-center justify-between gap-2 px-3 py-4 relative bg-container/29 rounded-xl border border-solid border-border cursor-pointer focus:outline-none focus:ring-2 focus:ring-black">
|
||||
<span className="inline-flex items-center gap-2.5 text-sm2">
|
||||
<TicketPercentIcon size={16} />
|
||||
|
||||
Reference in New Issue
Block a user