Addes bgtype
deploy to danak / build_and_deploy (push) Has been cancelled

This commit is contained in:
hamid zarghami
2026-06-22 12:22:34 +03:30
parent 18dcc5b2ba
commit c6e38184f5
2 changed files with 20 additions and 3 deletions
@@ -27,6 +27,12 @@ const normalizeBgUrl = (url: string) => {
return `${import.meta.env.VITE_BASE_URL}${url.startsWith("/") ? url : `/${url}`}`; 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 DesignSettings: FC = () => {
const [menuColor, setMenuColor] = useState("#000000"); const [menuColor, setMenuColor] = useState("#000000");
const [appliedColor, setAppliedColor] = useState("#000000"); const [appliedColor, setAppliedColor] = useState("#000000");
@@ -60,10 +66,15 @@ const DesignSettings: FC = () => {
setMenuColor(color); setMenuColor(color);
setAppliedColor(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); const matchingPattern = backgroundItems.find((item) => getBackgroundPatternUrl(item) === normalizeBgUrl(savedBgUrl) || getPatternBgUrl(item) === savedBgUrl);
if (matchingPattern) { if (matchingPattern && savedBgType !== "custom" && savedBgType !== "image") {
setBackgroundType("pattern"); setBackgroundType("pattern");
setSelectedPatternId(matchingPattern.id); setSelectedPatternId(matchingPattern.id);
} else { } else {
@@ -119,6 +130,7 @@ const DesignSettings: FC = () => {
const saveCustomBackground = (bgUrl: string) => { const saveCustomBackground = (bgUrl: string) => {
const backgroundPayload: SetBackgroundType = { const backgroundPayload: SetBackgroundType = {
bgUrl, bgUrl,
bgType: "custom",
bgBlur: String(imageBlur ?? 0), bgBlur: String(imageBlur ?? 0),
bgOverlay: String(overlayDarkness ?? 0), bgOverlay: String(overlayDarkness ?? 0),
}; };
@@ -157,7 +169,10 @@ const DesignSettings: FC = () => {
} }
setBackground( setBackground(
{ bgUrl }, {
bgUrl,
bgType: resolveBgType(backgroundType, selectedPatternId),
},
{ {
onSuccess: () => { onSuccess: () => {
toast.success("تنظیمات طراحی با موفقیت ذخیره شد"); toast.success("تنظیمات طراحی با موفقیت ذخیره شد");
+2
View File
@@ -41,6 +41,7 @@ export type Restaurant = {
address: string | null; address: string | null;
menuColor: string | null; menuColor: string | null;
bgUrl?: string | null; bgUrl?: string | null;
bgType?: "pattern" | "custom" | "color" | "image" | null;
bgOpacity?: string | null; bgOpacity?: string | null;
bgBlur?: string | null; bgBlur?: string | null;
bgOverlay?: string | null; bgOverlay?: string | null;
@@ -77,6 +78,7 @@ export type GetRestaurantResponse = IResponse<Restaurant>;
export type SetBackgroundType = { export type SetBackgroundType = {
bgUrl: string; bgUrl: string;
bgType: "pattern" | "custom" | "color";
bgOpacity?: string; bgOpacity?: string;
bgBlur?: string; bgBlur?: string;
bgOverlay?: string; bgOverlay?: string;