feat: plan limits, café location, nearby API, Iran map section
CI/CD / CI · API (dotnet build + test) (push) Successful in 56s
CI/CD / CI · Admin API (dotnet build) (push) Successful in 49s
CI/CD / CI · Dashboard (tsc) (push) Successful in 1m4s
CI/CD / CI · Admin Web (tsc) (push) Successful in 34s
CI/CD / CI · Website (tsc) (push) Successful in 44s
CI/CD / CI · Koja (tsc) (push) Successful in 50s
CI/CD / Deploy · all services (push) Successful in 3m15s

• PlanLimits: add MaxMenuCategories (Free→3), MaxMenuItems (Free→30),
  CanAccessCrm and CanAccessStatistics (Pro+ only)
• MenuController: enforce category/item limits before create (403 + PLAN_LIMIT_REACHED)
• Cafe entity + EF migration: Latitude/Longitude (double?, nullable)
• CafeSettingsController: PATCH accepts lat/lng with range validation
• PublicController: GET /api/public/map-markers (marketing SVG map feed)
  and GET /api/public/nearby (Koja nearby-cafés with Haversine sort)
• Dashboard settings: location card with OSM iframe preview + Neshan link
• Website homepage: IranMapSection — stylised SVG silhouette with
  SMIL-animated blinking dots at real café coordinates

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
soroush.asadi
2026-06-01 15:09:09 +03:30
parent 665e3ca279
commit 5e980cdfc0
12 changed files with 619 additions and 4 deletions
@@ -15,6 +15,23 @@ import { Input } from "@/components/ui/input";
import { LabeledField } from "@/components/ui/labeled-field";
import { notify } from "@/lib/notify";
// ── Location map preview ──────────────────────────────────────────────────────
function LocationMapPreview({ lat, lng }: { lat: number; lng: number }) {
const zoom = 15;
const src = `https://www.openstreetmap.org/export/embed.html?bbox=${lng - 0.01},${lat - 0.01},${lng + 0.01},${lat + 0.01}&layer=mapnik&marker=${lat},${lng}`;
return (
<div className="relative w-full overflow-hidden rounded-lg border" style={{ height: 220 }}>
<iframe
src={src}
title="location preview"
className="h-full w-full border-0"
loading="lazy"
allowFullScreen
/>
</div>
);
}
type SettingsShopPanelProps = {
cafeId: string;
};
@@ -33,9 +50,20 @@ export function SettingsShopPanel({ cafeId }: SettingsShopPanelProps) {
const [logoUrl, setLogoUrl] = useState("");
const [coverImageUrl, setCoverImageUrl] = useState("");
const [snappfoodVendorId, setSnappfoodVendorId] = useState("");
const [latInput, setLatInput] = useState("");
const [lngInput, setLngInput] = useState("");
const [locationError, setLocationError] = useState<string | null>(null);
const { data: cafeSettings } = useCafeSettings(cafeId);
const parsedLat = parseFloat(latInput);
const parsedLng = parseFloat(lngInput);
const hasValidLocation =
!isNaN(parsedLat) &&
!isNaN(parsedLng) &&
parsedLat >= 24 && parsedLat <= 40 &&
parsedLng >= 44 && parsedLng <= 64;
useEffect(() => {
if (!cafeSettings) return;
setName(cafeSettings.name ?? "");
@@ -47,6 +75,8 @@ export function SettingsShopPanel({ cafeId }: SettingsShopPanelProps) {
setLogoUrl(cafeSettings.logoUrl ?? "");
setCoverImageUrl(cafeSettings.coverImageUrl ?? "");
setSnappfoodVendorId(cafeSettings.snappfoodVendorId ?? "");
setLatInput(cafeSettings.latitude != null ? String(cafeSettings.latitude) : "");
setLngInput(cafeSettings.longitude != null ? String(cafeSettings.longitude) : "");
}, [cafeSettings]);
const saveProfile = useMutation({
@@ -83,6 +113,31 @@ export function SettingsShopPanel({ cafeId }: SettingsShopPanelProps) {
},
});
const saveLocation = useMutation({
mutationFn: () => {
setLocationError(null);
if (!hasValidLocation && (latInput || lngInput)) {
throw new Error("INVALID_LOCATION");
}
const body = latInput && lngInput && hasValidLocation
? { latitude: parsedLat, longitude: parsedLng }
: { clearLocation: true };
return apiPatch<CafeSettings>(`/api/cafes/${cafeId}/settings`, body);
},
onSuccess: (data) => {
queryClient.setQueryData(cafeSettingsQueryKey(cafeId), data);
notify.success("موقعیت ذخیره شد");
},
onError: (err: unknown) => {
const msg = err instanceof Error ? err.message : String(err);
if (msg === "INVALID_LOCATION" || msg.includes("INVALID_LOCATION")) {
setLocationError("مختصات نامعتبر است. مثال: عرض جغرافیایی ۳۵.۶۸۹، طول جغرافیایی ۵۱.۳۸۹");
} else {
notify.error("خطا در ذخیره موقعیت");
}
},
});
const uploadLogo = useMutation({
mutationFn: (file: File) =>
apiUpload<{ url: string }>(`/api/cafes/${cafeId}/media/cafe-logo`, file),
@@ -249,6 +304,80 @@ export function SettingsShopPanel({ cafeId }: SettingsShopPanelProps) {
</Button>
</CardContent>
</Card>
{/* Location card */}
<Card className="rounded-xl border border-border/80 shadow-sm">
<CardHeader className="px-6 pb-4 pt-6">
<CardTitle className="text-base font-medium">موقعیت روی نقشه</CardTitle>
</CardHeader>
<CardContent className="space-y-4 px-6 pb-6 pt-0">
<p className="text-sm leading-relaxed text-muted-foreground">
موقعیت دقیق کافه/رستوران خود را وارد کنید تا مشتریان بتوانند آن را پیدا کنند.
برای دریافت مختصات دقیق میتوانید از{" "}
<a
href={`https://neshan.org/maps/@${parsedLat || 35.6892},${parsedLng || 51.389},15z`}
target="_blank"
rel="noopener noreferrer"
className="text-primary underline"
>
نقشه نشان
</a>{" "}
استفاده کنید.
</p>
<div className="grid gap-4 sm:grid-cols-2">
<LabeledField label="عرض جغرافیایی (Latitude)" htmlFor="cafe-lat">
<Input
id="cafe-lat"
value={latInput}
onChange={(e) => { setLatInput(e.target.value); setLocationError(null); }}
placeholder="مثال: ۳۵.۶۸۹۲"
dir="ltr"
className="text-end"
inputMode="decimal"
/>
</LabeledField>
<LabeledField label="طول جغرافیایی (Longitude)" htmlFor="cafe-lng">
<Input
id="cafe-lng"
value={lngInput}
onChange={(e) => { setLngInput(e.target.value); setLocationError(null); }}
placeholder="مثال: ۵۱.۳۸۹"
dir="ltr"
className="text-end"
inputMode="decimal"
/>
</LabeledField>
</div>
{locationError && (
<p className="text-xs text-destructive">{locationError}</p>
)}
{hasValidLocation && (
<LocationMapPreview lat={parsedLat} lng={parsedLng} />
)}
<div className="flex flex-wrap gap-2">
<Button
className="bg-[#0F6E56] hover:bg-[#0c5e46]"
disabled={saveLocation.isPending}
onClick={() => saveLocation.mutate()}
>
ذخیره موقعیت
</Button>
{(latInput || lngInput) && (
<Button
variant="ghost"
size="sm"
onClick={() => { setLatInput(""); setLngInput(""); setLocationError(null); }}
>
پاک کردن موقعیت
</Button>
)}
</div>
</CardContent>
</Card>
</div>
);
}
@@ -18,6 +18,8 @@ export type CafeSettings = {
theme: CafeTheme;
defaultTaxRate?: number;
allowBranchTaxOverride?: boolean;
latitude?: number | null;
longitude?: number | null;
};
export function cafeSettingsQueryKey(cafeId: string) {