diff --git a/src/pages/settings/components/DesignSettings.tsx b/src/pages/settings/components/DesignSettings.tsx index 4719308..40290dc 100644 --- a/src/pages/settings/components/DesignSettings.tsx +++ b/src/pages/settings/components/DesignSettings.tsx @@ -27,6 +27,12 @@ const normalizeBgUrl = (url: string) => { return `${import.meta.env.VITE_BASE_URL}${url.startsWith("/") ? url : `/${url}`}`; }; +const resolveBgType = (type: BackgroundType, selectedPatternId: string | null): SetBackgroundType["bgType"] => { + if (type === "custom") return "custom"; + if (selectedPatternId === "0") return "color"; + return "pattern"; +}; + const DesignSettings: FC = () => { const [menuColor, setMenuColor] = useState("#000000"); const [appliedColor, setAppliedColor] = useState("#000000"); @@ -60,10 +66,15 @@ const DesignSettings: FC = () => { setMenuColor(color); setAppliedColor(color); - if (savedBgUrl) { + const savedBgType = restaurantData.bgType; + + if (savedBgType === "color" || (!savedBgUrl && savedBgType !== "custom" && savedBgType !== "image")) { + setBackgroundType("pattern"); + setSelectedPatternId("0"); + } else if (savedBgUrl) { const matchingPattern = backgroundItems.find((item) => getBackgroundPatternUrl(item) === normalizeBgUrl(savedBgUrl) || getPatternBgUrl(item) === savedBgUrl); - if (matchingPattern) { + if (matchingPattern && savedBgType !== "custom" && savedBgType !== "image") { setBackgroundType("pattern"); setSelectedPatternId(matchingPattern.id); } else { @@ -119,6 +130,7 @@ const DesignSettings: FC = () => { const saveCustomBackground = (bgUrl: string) => { const backgroundPayload: SetBackgroundType = { bgUrl, + bgType: "custom", bgBlur: String(imageBlur ?? 0), bgOverlay: String(overlayDarkness ?? 0), }; @@ -157,7 +169,10 @@ const DesignSettings: FC = () => { } setBackground( - { bgUrl }, + { + bgUrl, + bgType: resolveBgType(backgroundType, selectedPatternId), + }, { onSuccess: () => { toast.success("تنظیمات طراحی با موفقیت ذخیره شد"); diff --git a/src/pages/settings/types/Types.ts b/src/pages/settings/types/Types.ts index 7ec43b7..4a100cb 100644 --- a/src/pages/settings/types/Types.ts +++ b/src/pages/settings/types/Types.ts @@ -41,6 +41,7 @@ export type Restaurant = { address: string | null; menuColor: string | null; bgUrl?: string | null; + bgType?: "pattern" | "custom" | "color" | "image" | null; bgOpacity?: string | null; bgBlur?: string | null; bgOverlay?: string | null; @@ -77,6 +78,7 @@ export type GetRestaurantResponse = IResponse; export type SetBackgroundType = { bgUrl: string; + bgType: "pattern" | "custom" | "color"; bgOpacity?: string; bgBlur?: string; bgOverlay?: string;