feat: delete actions for warehouse/reservations/coupons/customers + Koja listing toggle
CI/CD / CI · API (dotnet build + test) (push) Successful in 1m10s
CI/CD / CI · Admin API (dotnet build) (push) Successful in 52s
CI/CD / CI · Dashboard (tsc) (push) Successful in 1m5s
CI/CD / CI · Admin Web (tsc) (push) Successful in 35s
CI/CD / CI · Website (tsc) (push) Successful in 45s
CI/CD / CI · Koja (tsc) (push) Successful in 55s
CI/CD / Deploy · all services (push) Successful in 3m29s
CI/CD / CI · API (dotnet build + test) (push) Successful in 1m10s
CI/CD / CI · Admin API (dotnet build) (push) Successful in 52s
CI/CD / CI · Dashboard (tsc) (push) Successful in 1m5s
CI/CD / CI · Admin Web (tsc) (push) Successful in 35s
CI/CD / CI · Website (tsc) (push) Successful in 45s
CI/CD / CI · Koja (tsc) (push) Successful in 55s
CI/CD / Deploy · all services (push) Successful in 3m29s
Delete (every manageable entity that only had "add" now has delete):
- Ingredients (warehouse): new DELETE /inventory/ingredients/{id} (soft-delete via
the global DeletedAt filter — no FK trouble with recipes/movements) + NoOp stub +
trash button in the materials cards.
- Reservations: new DELETE /reservations/{id} (soft-delete) + per-card delete button.
- Coupons & Customers: backend DELETE already existed; wired delete buttons in the UI.
- Shared ConfirmDialog component used by all delete flows (RTL-aware).
- Audit result: tables/branches/taxes/kitchen-stations/expenses/menu/terminals already
had delete; HR has no "add" so no delete needed; shifts intentionally excluded
(financial open/close records, not add-style entities).
Koja visibility:
- New Cafe.ShowOnKoja flag, default TRUE (DB default true so existing cafés stay
listed). Discover query now filters IsVerified && !Deleted && ShowOnKoja.
- public-profile GET/PUT expose showOnKoja; dashboard public-profile panel has an
on-by-default toggle that persists immediately. Platform IsVerified gate unchanged.
- EF migration AddCafeShowOnKoja (defaultValue: true).
Also: added the missing errors.generic i18n key (fa/en/ar) so useApiError's fallback
resolves instead of rendering the literal "errors.generic". 81 API tests pass.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -21,31 +21,11 @@
|
||||
"errorGeneric": "حدث خطأ. حاول مرة أخرى."
|
||||
},
|
||||
"errors": {
|
||||
"generic": "حدث خطأ. حاول مرة أخرى.",
|
||||
"REQUEST_FAILED": "فشل الطلب. حاول مرة أخرى.",
|
||||
"VALIDATION_ERROR": "البيانات المدخلة غير صالحة.",
|
||||
"FORBIDDEN": "ليس لديك إذن للقيام بذلك.",
|
||||
"OWNER_REQUIRED": "يمكن لمالك المقهى فقط القيام بذلك.",
|
||||
"MANAGER_REQUIRED": "يتطلب هذا الإجراء صلاحية المدير.",
|
||||
"PLAN_LIMIT_REACHED": "لقد بلغت حد باقتك. قم بالترقية للمتابعة.",
|
||||
"PLAN_FEATURE_DISABLED": "هذه الميزة غير متاحة في باقتك الحالية.",
|
||||
"NOT_FOUND": "غير موجود.",
|
||||
"ORDER_NOT_FOUND": "الطلب غير موجود.",
|
||||
"ITEM_NOT_FOUND": "العنصر غير موجود.",
|
||||
"ITEM_ALREADY_VOIDED": "تم إلغاء هذا العنصر بالفعل.",
|
||||
"ORDER_ALREADY_CLOSED": "هذا الطلب مغلق بالفعل.",
|
||||
"TABLE_OCCUPIED": "هذه الطاولة مشغولة حاليًا.",
|
||||
"TABLE_CLEANING": "هذه الطاولة قيد التنظيف.",
|
||||
"TABLE_NOT_FOUND": "الطاولة غير موجودة.",
|
||||
"TABLE_HAS_OPEN_ORDER": "هذه الطاولة لديها طلب مفتوح ولا يمكن حذفها.",
|
||||
"TABLE_SECTION_HAS_TABLES": "يحتوي هذا القسم على طاولات ولا يمكن حذفه.",
|
||||
"BRANCH_NOT_FOUND": "الفرع غير موجود.",
|
||||
"SECTION_NOT_FOUND": "القسم غير موجود.",
|
||||
"RATE_LIMITED": "طلبات كثيرة جدًا. يرجى الانتظار قليلاً.",
|
||||
"SMS_FAILED": "تعذّر إرسال الرسالة القصيرة. حاول مرة أخرى.",
|
||||
"INVALID_OTP": "رمز التحقق غير صالح أو منتهي الصلاحية.",
|
||||
"TICKET_CLOSED": "هذه التذكرة مغلقة ولا يمكنها استقبال الرسائل.",
|
||||
"ALREADY_REGISTERED": "يوجد حساب بالفعل لهذا الرقم. يرجى تسجيل الدخول."
|
||||
"planLimit": "وصلت إلى حد الخطة",
|
||||
"notFound": "غير موجود",
|
||||
"unauthorized": "غير مصرح",
|
||||
"network": "خطأ في الاتصال",
|
||||
"generic": "حدث خطأ. حاول مرة أخرى."
|
||||
},
|
||||
"brand": {
|
||||
"name": "ميزي"
|
||||
@@ -400,7 +380,10 @@
|
||||
"duplicatePhone": "رقم الجوال مسجل مسبقاً.",
|
||||
"generic": "تعذر الحفظ. حاول مرة أخرى."
|
||||
}
|
||||
}
|
||||
},
|
||||
"deleted": "تم حذف العميل",
|
||||
"deleteConfirmTitle": "حذف العميل",
|
||||
"deleteConfirmDesc": "هل أنت متأكد من حذف «{name}»؟"
|
||||
},
|
||||
"coupons": {
|
||||
"title": "القسائم",
|
||||
@@ -416,7 +399,10 @@
|
||||
"FixedAmount": "مبلغ ثابت",
|
||||
"FreeItem": "عنصر مجاني"
|
||||
},
|
||||
"noCoupons": "لا توجد قسائم"
|
||||
"noCoupons": "لا توجد قسائم",
|
||||
"deleted": "تم حذف القسيمة",
|
||||
"deleteConfirmTitle": "حذف القسيمة",
|
||||
"deleteConfirmDesc": "هل أنت متأكد من حذف القسيمة «{code}»؟"
|
||||
},
|
||||
"hr": {
|
||||
"title": "الموارد البشرية",
|
||||
@@ -863,7 +849,10 @@
|
||||
"purchasesThisMonth": "مشتريات المواد هذا الشهر",
|
||||
"purchaseCount": "{count} عملية شراء",
|
||||
"viewInExpenses": "عرض في المصروفات",
|
||||
"selectBranchForPurchases": "اختر الفرع من الشريط العلوي لتسجيل مشتريات المستودع."
|
||||
"selectBranchForPurchases": "اختر الفرع من الشريط العلوي لتسجيل مشتريات المستودع.",
|
||||
"deleted": "تم حذف المادة",
|
||||
"deleteConfirmTitle": "حذف المادة",
|
||||
"deleteConfirmDesc": "هل أنت متأكد من حذف «{name}»؟ لا يمكن التراجع."
|
||||
},
|
||||
"qr": {
|
||||
"brand": "ميزي",
|
||||
@@ -978,7 +967,10 @@
|
||||
"Cancelled": "ملغى",
|
||||
"Seated": "جالس",
|
||||
"Completed": "مكتمل"
|
||||
}
|
||||
},
|
||||
"deleted": "تم حذف الحجز",
|
||||
"deleteConfirmTitle": "حذف الحجز",
|
||||
"deleteConfirmDesc": "هل أنت متأكد من حذف حجز «{name}»؟"
|
||||
},
|
||||
"branchesPage": {
|
||||
"title": "الفروع",
|
||||
@@ -1394,12 +1386,6 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"errors": {
|
||||
"planLimit": "وصلت إلى حد الخطة",
|
||||
"notFound": "غير موجود",
|
||||
"unauthorized": "غير مصرح",
|
||||
"network": "خطأ في الاتصال"
|
||||
},
|
||||
"discoverPublic": {
|
||||
"brand": "ميزي",
|
||||
"title": "اكتشاف المقاهي",
|
||||
@@ -1546,5 +1532,9 @@
|
||||
"mid": "میانه",
|
||||
"premium": "پریمیوم"
|
||||
}
|
||||
},
|
||||
"cafePublicProfile": {
|
||||
"showOnKoja": "العرض على كوجا",
|
||||
"showOnKojaHint": "إدراج مقهاك في دليل كوجا العام (koja.meezi.ir). مفعّل افتراضيًا."
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,31 +21,11 @@
|
||||
"errorGeneric": "Something went wrong. Please try again."
|
||||
},
|
||||
"errors": {
|
||||
"generic": "Something went wrong. Please try again.",
|
||||
"REQUEST_FAILED": "Request failed. Please try again.",
|
||||
"VALIDATION_ERROR": "The information entered is invalid.",
|
||||
"FORBIDDEN": "You don't have permission to do this.",
|
||||
"OWNER_REQUIRED": "Only the café owner can do this.",
|
||||
"MANAGER_REQUIRED": "This action requires manager access.",
|
||||
"PLAN_LIMIT_REACHED": "You've reached your plan limit. Upgrade to continue.",
|
||||
"PLAN_FEATURE_DISABLED": "This feature isn't available on your current plan.",
|
||||
"NOT_FOUND": "Not found.",
|
||||
"ORDER_NOT_FOUND": "Order not found.",
|
||||
"ITEM_NOT_FOUND": "Item not found.",
|
||||
"ITEM_ALREADY_VOIDED": "This item is already voided.",
|
||||
"ORDER_ALREADY_CLOSED": "This order is already closed.",
|
||||
"TABLE_OCCUPIED": "This table is currently occupied.",
|
||||
"TABLE_CLEANING": "This table is being cleaned.",
|
||||
"TABLE_NOT_FOUND": "Table not found.",
|
||||
"TABLE_HAS_OPEN_ORDER": "This table has an open order and can't be removed.",
|
||||
"TABLE_SECTION_HAS_TABLES": "This section has tables and can't be removed.",
|
||||
"BRANCH_NOT_FOUND": "Branch not found.",
|
||||
"SECTION_NOT_FOUND": "Section not found.",
|
||||
"RATE_LIMITED": "Too many requests. Please wait a moment.",
|
||||
"SMS_FAILED": "Could not send the SMS. Please try again.",
|
||||
"INVALID_OTP": "Invalid or expired verification code.",
|
||||
"TICKET_CLOSED": "This ticket is closed and can't receive messages.",
|
||||
"ALREADY_REGISTERED": "An account already exists for this number. Please sign in."
|
||||
"planLimit": "Plan limit reached. Please upgrade.",
|
||||
"notFound": "Not found",
|
||||
"unauthorized": "Unauthorized",
|
||||
"network": "Network error",
|
||||
"generic": "Something went wrong. Please try again."
|
||||
},
|
||||
"brand": {
|
||||
"name": "Meezi"
|
||||
@@ -419,7 +399,10 @@
|
||||
"duplicatePhone": "This phone number is already registered.",
|
||||
"generic": "Could not save. Please try again."
|
||||
}
|
||||
}
|
||||
},
|
||||
"deleted": "Customer deleted",
|
||||
"deleteConfirmTitle": "Delete customer",
|
||||
"deleteConfirmDesc": "Delete “{name}”?"
|
||||
},
|
||||
"coupons": {
|
||||
"title": "Coupons",
|
||||
@@ -435,7 +418,10 @@
|
||||
"FixedAmount": "Fixed amount",
|
||||
"FreeItem": "Free item"
|
||||
},
|
||||
"noCoupons": "No coupons yet"
|
||||
"noCoupons": "No coupons yet",
|
||||
"deleted": "Coupon deleted",
|
||||
"deleteConfirmTitle": "Delete coupon",
|
||||
"deleteConfirmDesc": "Delete coupon “{code}”?"
|
||||
},
|
||||
"hr": {
|
||||
"title": "Human resources",
|
||||
@@ -932,7 +918,10 @@
|
||||
"purchasesThisMonth": "Material purchases this month",
|
||||
"purchaseCount": "{count} purchases",
|
||||
"viewInExpenses": "View in expenses",
|
||||
"selectBranchForPurchases": "Select a branch in the top bar to record warehouse purchases."
|
||||
"selectBranchForPurchases": "Select a branch in the top bar to record warehouse purchases.",
|
||||
"deleted": "Material deleted",
|
||||
"deleteConfirmTitle": "Delete material",
|
||||
"deleteConfirmDesc": "Delete “{name}”? This can’t be undone."
|
||||
},
|
||||
"qr": {
|
||||
"brand": "Meezi",
|
||||
@@ -1048,7 +1037,10 @@
|
||||
"Cancelled": "Cancelled",
|
||||
"Seated": "Seated",
|
||||
"Completed": "Completed"
|
||||
}
|
||||
},
|
||||
"deleted": "Reservation deleted",
|
||||
"deleteConfirmTitle": "Delete reservation",
|
||||
"deleteConfirmDesc": "Delete the reservation for “{name}”?"
|
||||
},
|
||||
"branchesPage": {
|
||||
"title": "Branches",
|
||||
@@ -1476,12 +1468,6 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"errors": {
|
||||
"planLimit": "Plan limit reached. Please upgrade.",
|
||||
"notFound": "Not found",
|
||||
"unauthorized": "Unauthorized",
|
||||
"network": "Network error"
|
||||
},
|
||||
"discoverPublic": {
|
||||
"brand": "Meezi",
|
||||
"title": "Discover cafés",
|
||||
@@ -1586,7 +1572,9 @@
|
||||
"save": "Save",
|
||||
"saved": "Saved",
|
||||
"saveFailed": "Save failed",
|
||||
"loading": "Loading…"
|
||||
"loading": "Loading…",
|
||||
"showOnKoja": "Show on Koja",
|
||||
"showOnKojaHint": "List your café in the public Koja directory (koja.meezi.ir). On by default."
|
||||
},
|
||||
"discoverProfile": {
|
||||
"sections": {
|
||||
|
||||
@@ -21,31 +21,11 @@
|
||||
"errorGeneric": "خطایی رخ داد. دوباره تلاش کنید."
|
||||
},
|
||||
"errors": {
|
||||
"generic": "خطایی رخ داد. دوباره تلاش کنید.",
|
||||
"REQUEST_FAILED": "درخواست ناموفق بود. دوباره تلاش کنید.",
|
||||
"VALIDATION_ERROR": "اطلاعات واردشده نامعتبر است.",
|
||||
"FORBIDDEN": "شما اجازه این کار را ندارید.",
|
||||
"OWNER_REQUIRED": "فقط مالک کافه میتواند این کار را انجام دهد.",
|
||||
"MANAGER_REQUIRED": "این عملیات نیاز به دسترسی مدیر دارد.",
|
||||
"PLAN_LIMIT_REACHED": "محدودیت پلن شما پر شده است. برای ادامه پلن را ارتقا دهید.",
|
||||
"PLAN_FEATURE_DISABLED": "این قابلیت در پلن فعلی شما فعال نیست.",
|
||||
"NOT_FOUND": "مورد موردنظر یافت نشد.",
|
||||
"ORDER_NOT_FOUND": "سفارش یافت نشد.",
|
||||
"ITEM_NOT_FOUND": "آیتم یافت نشد.",
|
||||
"ITEM_ALREADY_VOIDED": "این آیتم قبلاً ابطال شده است.",
|
||||
"ORDER_ALREADY_CLOSED": "این سفارش بسته شده است.",
|
||||
"TABLE_OCCUPIED": "این میز هماکنون مشغول است.",
|
||||
"TABLE_CLEANING": "این میز در حال نظافت است.",
|
||||
"TABLE_NOT_FOUND": "میز یافت نشد.",
|
||||
"TABLE_HAS_OPEN_ORDER": "این میز سفارش باز دارد و قابل حذف نیست.",
|
||||
"TABLE_SECTION_HAS_TABLES": "این بخش دارای میز است و قابل حذف نیست.",
|
||||
"BRANCH_NOT_FOUND": "شعبه یافت نشد.",
|
||||
"SECTION_NOT_FOUND": "بخش یافت نشد.",
|
||||
"RATE_LIMITED": "تعداد درخواست بیش از حد مجاز است. کمی صبر کنید.",
|
||||
"SMS_FAILED": "ارسال پیامک ناموفق بود. دوباره تلاش کنید.",
|
||||
"INVALID_OTP": "کد تأیید نامعتبر یا منقضی شده است.",
|
||||
"TICKET_CLOSED": "این تیکت بسته شده و امکان ارسال پیام ندارد.",
|
||||
"ALREADY_REGISTERED": "برای این شماره قبلاً حساب ساخته شده است. وارد شوید."
|
||||
"planLimit": "به سقف پلن رسیدهاید. برای ادامه ارتقا دهید",
|
||||
"notFound": "یافت نشد",
|
||||
"unauthorized": "دسترسی ندارید",
|
||||
"network": "خطای ارتباط با سرور",
|
||||
"generic": "خطایی رخ داد. دوباره تلاش کنید."
|
||||
},
|
||||
"brand": {
|
||||
"name": "میزی"
|
||||
@@ -419,7 +399,10 @@
|
||||
"duplicatePhone": "این شماره موبایل قبلاً ثبت شده است.",
|
||||
"generic": "ذخیره انجام نشد. دوباره تلاش کنید."
|
||||
}
|
||||
}
|
||||
},
|
||||
"deleted": "مشتری حذف شد",
|
||||
"deleteConfirmTitle": "حذف مشتری",
|
||||
"deleteConfirmDesc": "آیا از حذف «{name}» مطمئن هستید؟"
|
||||
},
|
||||
"coupons": {
|
||||
"title": "کوپنها",
|
||||
@@ -435,7 +418,10 @@
|
||||
"FixedAmount": "مبلغ ثابت",
|
||||
"FreeItem": "آیتم رایگان"
|
||||
},
|
||||
"noCoupons": "کوپنی ثبت نشده"
|
||||
"noCoupons": "کوپنی ثبت نشده",
|
||||
"deleted": "کوپن حذف شد",
|
||||
"deleteConfirmTitle": "حذف کوپن",
|
||||
"deleteConfirmDesc": "آیا از حذف کوپن «{code}» مطمئن هستید؟"
|
||||
},
|
||||
"hr": {
|
||||
"title": "منابع انسانی",
|
||||
@@ -932,7 +918,10 @@
|
||||
"purchasesThisMonth": "خرید مواد این ماه",
|
||||
"purchaseCount": "{count} خرید",
|
||||
"viewInExpenses": "مشاهده در هزینهها",
|
||||
"selectBranchForPurchases": "برای ثبت خرید انبار، ابتدا شعبه را از نوار بالا انتخاب کنید."
|
||||
"selectBranchForPurchases": "برای ثبت خرید انبار، ابتدا شعبه را از نوار بالا انتخاب کنید.",
|
||||
"deleted": "ماده حذف شد",
|
||||
"deleteConfirmTitle": "حذف ماده",
|
||||
"deleteConfirmDesc": "آیا از حذف «{name}» مطمئن هستید؟ این عمل قابل بازگشت نیست."
|
||||
},
|
||||
"qr": {
|
||||
"brand": "میزی",
|
||||
@@ -1049,7 +1038,10 @@
|
||||
"Cancelled": "لغو شده",
|
||||
"Seated": "نشسته",
|
||||
"Completed": "انجام شده"
|
||||
}
|
||||
},
|
||||
"deleted": "رزرو حذف شد",
|
||||
"deleteConfirmTitle": "حذف رزرو",
|
||||
"deleteConfirmDesc": "آیا از حذف رزرو «{name}» مطمئن هستید؟"
|
||||
},
|
||||
"branchesPage": {
|
||||
"title": "شعب",
|
||||
@@ -1477,12 +1469,6 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"errors": {
|
||||
"planLimit": "به سقف پلن رسیدهاید. برای ادامه ارتقا دهید",
|
||||
"notFound": "یافت نشد",
|
||||
"unauthorized": "دسترسی ندارید",
|
||||
"network": "خطای ارتباط با سرور"
|
||||
},
|
||||
"discoverPublic": {
|
||||
"brand": "میزی",
|
||||
"title": "کافهیاب",
|
||||
@@ -1587,7 +1573,9 @@
|
||||
"save": "ذخیره",
|
||||
"saved": "ذخیره شد",
|
||||
"saveFailed": "ذخیره ناموفق بود",
|
||||
"loading": "در حال بارگذاری…"
|
||||
"loading": "در حال بارگذاری…",
|
||||
"showOnKoja": "نمایش در کوجا",
|
||||
"showOnKojaHint": "کافه شما در فهرست عمومی کوجا (koja.meezi.ir) نمایش داده شود. پیشفرض روشن است."
|
||||
},
|
||||
"discoverProfile": {
|
||||
"sections": {
|
||||
|
||||
@@ -3,24 +3,29 @@
|
||||
import { useState } from "react";
|
||||
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { Plus } from "lucide-react";
|
||||
import { apiGet, apiPost } from "@/lib/api/client";
|
||||
import { Plus, Trash2 } from "lucide-react";
|
||||
import { apiDelete, apiGet, apiPost } from "@/lib/api/client";
|
||||
import type { Coupon, CouponType } from "@/lib/api/types";
|
||||
import { useAuthStore } from "@/lib/stores/auth.store";
|
||||
import { formatNumber } from "@/lib/format";
|
||||
import { notify } from "@/lib/notify";
|
||||
import { useApiError } from "@/lib/use-api-error";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { LabeledField } from "@/components/ui/labeled-field";
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { ConfirmDialog } from "@/components/ui/confirm-dialog";
|
||||
|
||||
export function CouponsScreen() {
|
||||
const t = useTranslations("coupons");
|
||||
const tCommon = useTranslations("common");
|
||||
const apiError = useApiError();
|
||||
const cafeId = useAuthStore((s) => s.user?.cafeId);
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
const [showForm, setShowForm] = useState(false);
|
||||
const [deleteTarget, setDeleteTarget] = useState<Coupon | null>(null);
|
||||
const [code, setCode] = useState("");
|
||||
const [type, setType] = useState<CouponType>("Percentage");
|
||||
const [value, setValue] = useState("10");
|
||||
@@ -47,6 +52,16 @@ export function CouponsScreen() {
|
||||
},
|
||||
});
|
||||
|
||||
const deleteCoupon = useMutation({
|
||||
mutationFn: (id: string) => apiDelete(`/api/cafes/${cafeId}/coupons/${id}`),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["coupons", cafeId] });
|
||||
setDeleteTarget(null);
|
||||
notify.success(t("deleted"));
|
||||
},
|
||||
onError: (err) => notify.error(apiError(err)),
|
||||
});
|
||||
|
||||
if (!cafeId) return null;
|
||||
|
||||
return (
|
||||
@@ -132,11 +147,34 @@ export function CouponsScreen() {
|
||||
{t("usage")}: {formatNumber(c.usedCount)}
|
||||
{c.usageLimit ? ` / ${formatNumber(c.usageLimit)}` : ""}
|
||||
</p>
|
||||
<div className="mt-2 flex justify-end">
|
||||
<Button
|
||||
type="button"
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
className="text-red-600 hover:bg-red-50 hover:text-red-700"
|
||||
onClick={() => setDeleteTarget(c)}
|
||||
>
|
||||
<Trash2 className="me-1.5 size-4" />
|
||||
{tCommon("delete")}
|
||||
</Button>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<ConfirmDialog
|
||||
open={!!deleteTarget}
|
||||
onOpenChange={(o) => {
|
||||
if (!o) setDeleteTarget(null);
|
||||
}}
|
||||
title={t("deleteConfirmTitle")}
|
||||
description={deleteTarget ? t("deleteConfirmDesc", { code: deleteTarget.code }) : undefined}
|
||||
busy={deleteCoupon.isPending}
|
||||
onConfirm={() => deleteTarget && deleteCoupon.mutate(deleteTarget.id)}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,23 +1,27 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { Plus, Pencil, Search } from "lucide-react";
|
||||
import { apiGet } from "@/lib/api/client";
|
||||
import { Plus, Pencil, Search, Trash2 } from "lucide-react";
|
||||
import { apiDelete, apiGet } from "@/lib/api/client";
|
||||
import type { Customer } from "@/lib/api/types";
|
||||
import { useAuthStore } from "@/lib/stores/auth.store";
|
||||
import { formatNumber } from "@/lib/format";
|
||||
import { notify } from "@/lib/notify";
|
||||
import { useApiError } from "@/lib/use-api-error";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { LabeledField } from "@/components/ui/labeled-field";
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { ConfirmDialog } from "@/components/ui/confirm-dialog";
|
||||
import { CustomerWizard, type CustomerWizardMode } from "@/components/crm/customer-wizard";
|
||||
|
||||
export function CrmScreen() {
|
||||
const t = useTranslations("crm");
|
||||
const tCommon = useTranslations("common");
|
||||
const apiError = useApiError();
|
||||
const cafeId = useAuthStore((s) => s.user?.cafeId);
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
@@ -26,6 +30,7 @@ export function CrmScreen() {
|
||||
const [wizardOpen, setWizardOpen] = useState(false);
|
||||
const [wizardMode, setWizardMode] = useState<CustomerWizardMode>("create");
|
||||
const [editingCustomer, setEditingCustomer] = useState<Customer | null>(null);
|
||||
const [deleteTarget, setDeleteTarget] = useState<Customer | null>(null);
|
||||
|
||||
const { data: customers = [], isLoading } = useQuery({
|
||||
queryKey: ["customers", cafeId, debouncedSearch],
|
||||
@@ -46,6 +51,16 @@ export function CrmScreen() {
|
||||
queryClient.invalidateQueries({ queryKey: ["customers", cafeId] });
|
||||
};
|
||||
|
||||
const deleteCustomer = useMutation({
|
||||
mutationFn: (id: string) => apiDelete(`/api/cafes/${cafeId}/customers/${id}`),
|
||||
onSuccess: () => {
|
||||
refreshCustomers();
|
||||
setDeleteTarget(null);
|
||||
notify.success(t("deleted"));
|
||||
},
|
||||
onError: (err) => notify.error(apiError(err)),
|
||||
});
|
||||
|
||||
if (!cafeId) return null;
|
||||
|
||||
return (
|
||||
@@ -104,21 +119,43 @@ export function CrmScreen() {
|
||||
{t("loyaltyPoints")}: {formatNumber(c.loyaltyPoints)}
|
||||
</p>
|
||||
</div>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
className="w-full"
|
||||
onClick={() => openWizard("edit", c)}
|
||||
>
|
||||
<Pencil className="me-1 h-3.5 w-3.5" />
|
||||
{tCommon("edit")}
|
||||
</Button>
|
||||
<div className="flex gap-2">
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
className="flex-1"
|
||||
onClick={() => openWizard("edit", c)}
|
||||
>
|
||||
<Pencil className="me-1 h-3.5 w-3.5" />
|
||||
{tCommon("edit")}
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
className="text-red-600 hover:bg-red-50 hover:text-red-700"
|
||||
aria-label={tCommon("delete")}
|
||||
onClick={() => setDeleteTarget(c)}
|
||||
>
|
||||
<Trash2 className="h-3.5 w-3.5" />
|
||||
</Button>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<ConfirmDialog
|
||||
open={!!deleteTarget}
|
||||
onOpenChange={(o) => {
|
||||
if (!o) setDeleteTarget(null);
|
||||
}}
|
||||
title={t("deleteConfirmTitle")}
|
||||
description={deleteTarget ? t("deleteConfirmDesc", { name: deleteTarget.name }) : undefined}
|
||||
busy={deleteCustomer.isPending}
|
||||
onConfirm={() => deleteTarget && deleteCustomer.mutate(deleteTarget.id)}
|
||||
/>
|
||||
|
||||
<CustomerWizard
|
||||
open={wizardOpen}
|
||||
mode={wizardMode}
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
updateCafePublicProfile,
|
||||
uploadGalleryPhoto,
|
||||
type CafeProfileEdit,
|
||||
type UpdateCafeProfilePayload,
|
||||
} from "@/lib/api/cafe-public-profile";
|
||||
import type { WorkingHours } from "@/lib/api/public-discover";
|
||||
import { resolveMediaUrl } from "@/lib/api/client";
|
||||
@@ -42,6 +43,7 @@ export function CafePublicProfilePanel({ cafeId }: Props) {
|
||||
const [instagram, setInstagram] = useState<string>("");
|
||||
const [website, setWebsite] = useState<string>("");
|
||||
const [hours, setHours] = useState<WorkingHours>(emptyHours());
|
||||
const [showOnKoja, setShowOnKoja] = useState(true);
|
||||
const [initialized, setInitialized] = useState(false);
|
||||
|
||||
// Populate local state once we get server data
|
||||
@@ -50,17 +52,20 @@ export function CafePublicProfilePanel({ cafeId }: Props) {
|
||||
setInstagram(profile.instagramHandle ?? "");
|
||||
setWebsite(profile.websiteUrl ?? "");
|
||||
setHours(profile.workingHours ?? emptyHours());
|
||||
setShowOnKoja(profile.showOnKoja ?? true);
|
||||
setInitialized(true);
|
||||
}
|
||||
|
||||
// ── Save info/social/hours ────────────────────────────────────────────────
|
||||
const saveMutation = useMutation({
|
||||
mutationFn: () =>
|
||||
mutationFn: (override?: Partial<UpdateCafeProfilePayload>) =>
|
||||
updateCafePublicProfile(cafeId, {
|
||||
description,
|
||||
instagramHandle: instagram || null,
|
||||
websiteUrl: website || null,
|
||||
workingHours: hours,
|
||||
showOnKoja,
|
||||
...override,
|
||||
}),
|
||||
onSuccess: (data) => {
|
||||
qc.setQueryData(["cafe-public-profile", cafeId], data);
|
||||
@@ -157,6 +162,23 @@ export function CafePublicProfilePanel({ cafeId }: Props) {
|
||||
{tab === "info" && (
|
||||
<Card className="rounded-xl border border-border/80">
|
||||
<CardContent className="space-y-4 p-4">
|
||||
<label className="flex cursor-pointer items-center justify-between gap-3 rounded-lg border border-[#0F6E56]/25 bg-[#E1F5EE]/40 px-3 py-2.5">
|
||||
<span className="min-w-0">
|
||||
<span className="block text-sm font-medium">{t("showOnKoja")}</span>
|
||||
<span className="block text-xs text-muted-foreground">{t("showOnKojaHint")}</span>
|
||||
</span>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={showOnKoja}
|
||||
onChange={(e) => {
|
||||
const v = e.target.checked;
|
||||
setShowOnKoja(v);
|
||||
// Persist immediately (pass the new value to avoid stale state).
|
||||
saveMutation.mutate({ showOnKoja: v });
|
||||
}}
|
||||
className="h-5 w-5 shrink-0 cursor-pointer accent-[#0F6E56]"
|
||||
/>
|
||||
</label>
|
||||
<div className="space-y-1">
|
||||
<Label>{t("description")}</Label>
|
||||
<textarea
|
||||
@@ -167,7 +189,7 @@ export function CafePublicProfilePanel({ cafeId }: Props) {
|
||||
className="w-full resize-none rounded-lg border border-border/80 bg-white px-3 py-2 text-sm focus:outline-none focus:ring-1 focus:ring-[#0F6E56]"
|
||||
/>
|
||||
</div>
|
||||
<SaveButton saving={saveMutation.isPending} saved={saved} onSave={() => saveMutation.mutate()} t={t} />
|
||||
<SaveButton saving={saveMutation.isPending} saved={saved} onSave={() => saveMutation.mutate(undefined)} t={t} />
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
@@ -276,7 +298,7 @@ export function CafePublicProfilePanel({ cafeId }: Props) {
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
<SaveButton saving={saveMutation.isPending} saved={saved} onSave={() => saveMutation.mutate()} t={t} />
|
||||
<SaveButton saving={saveMutation.isPending} saved={saved} onSave={() => saveMutation.mutate(undefined)} t={t} />
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
@@ -307,7 +329,7 @@ export function CafePublicProfilePanel({ cafeId }: Props) {
|
||||
dir="ltr"
|
||||
/>
|
||||
</div>
|
||||
<SaveButton saving={saveMutation.isPending} saved={saved} onSave={() => saveMutation.mutate()} t={t} />
|
||||
<SaveButton saving={saveMutation.isPending} saved={saved} onSave={() => saveMutation.mutate(undefined)} t={t} />
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
@@ -4,9 +4,10 @@ import { useEffect, useMemo, useState } from "react";
|
||||
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import { useTranslations, useLocale } from "next-intl";
|
||||
import { Link } from "@/i18n/routing";
|
||||
import { Pencil } from "lucide-react";
|
||||
import { Pencil, Trash2 } from "lucide-react";
|
||||
import { DemoDataBanner } from "@/components/demo/demo-data-banner";
|
||||
import { apiGet, apiPatch, apiPost, apiPut } from "@/lib/api/client";
|
||||
import { ConfirmDialog } from "@/components/ui/confirm-dialog";
|
||||
import { apiDelete, apiGet, apiPatch, apiPost, apiPut } from "@/lib/api/client";
|
||||
import { InventoryUnitField } from "@/components/inventory/inventory-unit-field";
|
||||
import { useAuthStore } from "@/lib/stores/auth.store";
|
||||
import { useBranchStore } from "@/lib/stores/branch.store";
|
||||
@@ -19,6 +20,7 @@ import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { notify } from "@/lib/notify";
|
||||
import { useApiError } from "@/lib/use-api-error";
|
||||
|
||||
type Ingredient = {
|
||||
id: string;
|
||||
@@ -67,6 +69,7 @@ type PurchasesSummary = {
|
||||
export function InventoryScreen() {
|
||||
const t = useTranslations("inventory");
|
||||
const tCommon = useTranslations("common");
|
||||
const apiError = useApiError();
|
||||
const locale = useLocale();
|
||||
const numberLocale = locale === "en" ? "en-US" : "fa-IR";
|
||||
const cafeId = useAuthStore((s) => s.user?.cafeId);
|
||||
@@ -95,6 +98,7 @@ export function InventoryScreen() {
|
||||
const [adjustQty, setAdjustQty] = useState<Record<string, string>>({});
|
||||
const [adjustPaid, setAdjustPaid] = useState<Record<string, string>>({});
|
||||
const [editingId, setEditingId] = useState<string | null>(null);
|
||||
const [deleteTarget, setDeleteTarget] = useState<Ingredient | null>(null);
|
||||
const [editName, setEditName] = useState("");
|
||||
const [editUnit, setEditUnit] = useState("گرم");
|
||||
const [editReorder, setEditReorder] = useState("0");
|
||||
@@ -198,6 +202,17 @@ export function InventoryScreen() {
|
||||
},
|
||||
});
|
||||
|
||||
const deleteIngredient = useMutation({
|
||||
mutationFn: (id: string) =>
|
||||
apiDelete(`/api/cafes/${cafeId}/inventory/ingredients/${id}`),
|
||||
onSuccess: () => {
|
||||
void qc.invalidateQueries({ queryKey: ["inventory", cafeId] });
|
||||
setDeleteTarget(null);
|
||||
notify.success(t("deleted"));
|
||||
},
|
||||
onError: (err) => notify.error(apiError(err)),
|
||||
});
|
||||
|
||||
const adjustStock = useMutation({
|
||||
mutationFn: ({ id, delta, paid }: { id: string; delta: number; paid?: number }) =>
|
||||
apiPost(`/api/cafes/${cafeId}/inventory/ingredients/${id}/adjust`, {
|
||||
@@ -478,6 +493,16 @@ export function InventoryScreen() {
|
||||
>
|
||||
<Pencil className="size-4" />
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
className="size-8 text-red-600 hover:bg-red-50 hover:text-red-700"
|
||||
aria-label={tCommon("delete")}
|
||||
onClick={() => setDeleteTarget(ing)}
|
||||
>
|
||||
<Trash2 className="size-4" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<p className="text-sm font-medium text-[#0F6E56]">
|
||||
@@ -661,6 +686,17 @@ export function InventoryScreen() {
|
||||
) : null}
|
||||
</Card>
|
||||
)}
|
||||
|
||||
<ConfirmDialog
|
||||
open={!!deleteTarget}
|
||||
onOpenChange={(o) => {
|
||||
if (!o) setDeleteTarget(null);
|
||||
}}
|
||||
title={t("deleteConfirmTitle")}
|
||||
description={deleteTarget ? t("deleteConfirmDesc", { name: deleteTarget.name }) : undefined}
|
||||
busy={deleteIngredient.isPending}
|
||||
onConfirm={() => deleteTarget && deleteIngredient.mutate(deleteTarget.id)}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,11 @@ import { useState } from "react";
|
||||
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { Link } from "@/i18n/routing";
|
||||
import { apiGet, apiPatch, apiPost } from "@/lib/api/client";
|
||||
import { Trash2 } from "lucide-react";
|
||||
import { apiDelete, apiGet, apiPatch, apiPost } from "@/lib/api/client";
|
||||
import { ConfirmDialog } from "@/components/ui/confirm-dialog";
|
||||
import { notify } from "@/lib/notify";
|
||||
import { useApiError } from "@/lib/use-api-error";
|
||||
import { useAuthStore } from "@/lib/stores/auth.store";
|
||||
import { formatNumber } from "@/lib/format";
|
||||
import { Button } from "@/components/ui/button";
|
||||
@@ -45,8 +49,11 @@ const statusStyle: Record<ReservationStatus, string> = {
|
||||
|
||||
export function ReservationsScreen() {
|
||||
const t = useTranslations("reservations");
|
||||
const tCommon = useTranslations("common");
|
||||
const apiError = useApiError();
|
||||
const cafeId = useAuthStore((s) => s.user?.cafeId);
|
||||
const queryClient = useQueryClient();
|
||||
const [deleteTarget, setDeleteTarget] = useState<Reservation | null>(null);
|
||||
|
||||
const [guestName, setGuestName] = useState("");
|
||||
const [guestPhone, setGuestPhone] = useState("09121234567");
|
||||
@@ -92,6 +99,16 @@ export function ReservationsScreen() {
|
||||
onSuccess: () => queryClient.invalidateQueries({ queryKey: ["reservations", cafeId] }),
|
||||
});
|
||||
|
||||
const deleteReservation = useMutation({
|
||||
mutationFn: (id: string) => apiDelete(`/api/cafes/${cafeId}/reservations/${id}`),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["reservations", cafeId] });
|
||||
setDeleteTarget(null);
|
||||
notify.success(t("deleted"));
|
||||
},
|
||||
onError: (err) => notify.error(apiError(err)),
|
||||
});
|
||||
|
||||
if (!cafeId) return null;
|
||||
|
||||
const posHref = (r: Reservation) => {
|
||||
@@ -245,6 +262,15 @@ export function ReservationsScreen() {
|
||||
{t("markCompleted")}
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
className="text-red-600 hover:bg-red-50 hover:text-red-700"
|
||||
aria-label={tCommon("delete")}
|
||||
onClick={() => setDeleteTarget(r)}
|
||||
>
|
||||
<Trash2 className="size-4" />
|
||||
</Button>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
@@ -252,6 +278,19 @@ export function ReservationsScreen() {
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
|
||||
<ConfirmDialog
|
||||
open={!!deleteTarget}
|
||||
onOpenChange={(o) => {
|
||||
if (!o) setDeleteTarget(null);
|
||||
}}
|
||||
title={t("deleteConfirmTitle")}
|
||||
description={
|
||||
deleteTarget ? t("deleteConfirmDesc", { name: deleteTarget.guestName }) : undefined
|
||||
}
|
||||
busy={deleteReservation.isPending}
|
||||
onConfirm={() => deleteTarget && deleteReservation.mutate(deleteTarget.id)}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
"use client";
|
||||
|
||||
import { useTranslations } from "next-intl";
|
||||
import { useIsRtl } from "@/lib/use-is-rtl";
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from "@/components/ui/alert-dialog";
|
||||
|
||||
/**
|
||||
* Shared confirmation dialog (used for destructive delete actions across screens).
|
||||
* Keeps the dialog open while `busy` so the row stays until the mutation resolves;
|
||||
* the caller closes it via onOpenChange(false) on success.
|
||||
*/
|
||||
export function ConfirmDialog({
|
||||
open,
|
||||
onOpenChange,
|
||||
title,
|
||||
description,
|
||||
confirmLabel,
|
||||
onConfirm,
|
||||
busy = false,
|
||||
destructive = true,
|
||||
}: {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
title: string;
|
||||
description?: string;
|
||||
confirmLabel?: string;
|
||||
onConfirm: () => void;
|
||||
busy?: boolean;
|
||||
destructive?: boolean;
|
||||
}) {
|
||||
const tCommon = useTranslations("common");
|
||||
const isRtl = useIsRtl();
|
||||
|
||||
return (
|
||||
<AlertDialog open={open} onOpenChange={onOpenChange}>
|
||||
<AlertDialogContent dir={isRtl ? "rtl" : "ltr"}>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>{title}</AlertDialogTitle>
|
||||
{description ? (
|
||||
<AlertDialogDescription>{description}</AlertDialogDescription>
|
||||
) : null}
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>{tCommon("cancel")}</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
className={destructive ? "bg-red-600 text-white hover:bg-red-700" : ""}
|
||||
disabled={busy}
|
||||
onClick={(e) => {
|
||||
e.preventDefault(); // keep open until the mutation resolves
|
||||
onConfirm();
|
||||
}}
|
||||
>
|
||||
{busy ? tCommon("loading") : confirmLabel ?? tCommon("delete")}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
);
|
||||
}
|
||||
@@ -8,6 +8,7 @@ export type CafeProfileEdit = {
|
||||
instagramHandle: string | null;
|
||||
websiteUrl: string | null;
|
||||
workingHours: WorkingHours | null;
|
||||
showOnKoja: boolean;
|
||||
};
|
||||
|
||||
export type UpdateCafeProfilePayload = {
|
||||
@@ -15,6 +16,7 @@ export type UpdateCafeProfilePayload = {
|
||||
instagramHandle?: string | null;
|
||||
websiteUrl?: string | null;
|
||||
workingHours?: WorkingHours | null;
|
||||
showOnKoja?: boolean;
|
||||
};
|
||||
|
||||
async function unwrap<T>(promise: Promise<{ data: ApiResponse<T> }>): Promise<T> {
|
||||
|
||||
Reference in New Issue
Block a user