feat: allow updating custom menu slug with format validation, uniqueness checking and active cache sync
This commit is contained in:
@@ -18,7 +18,7 @@ import * as Haptics from "expo-haptics";
|
||||
import * as ImagePicker from "expo-image-picker";
|
||||
import { api } from "@/lib/api";
|
||||
import { supabase } from "@/lib/supabase";
|
||||
import { getActiveRestaurant, clearActiveRestaurant, type ActiveRestaurant } from "@/lib/active-restaurant";
|
||||
import { getActiveRestaurant, setActiveRestaurant, clearActiveRestaurant, type ActiveRestaurant } from "@/lib/active-restaurant";
|
||||
import { getPublicMenuUrl, getPublicMenuDisplayUrl } from "@/lib/urls";
|
||||
|
||||
interface RestaurantDetail {
|
||||
@@ -174,14 +174,24 @@ export default function AccountScreen() {
|
||||
setSavingRest(true);
|
||||
Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Medium).catch(() => {});
|
||||
try {
|
||||
await api.patch(`/restaurants/${active.restaurantId}`, {
|
||||
const updated = await api.patch<RestaurantDetail>(`/restaurants/${active.restaurantId}`, {
|
||||
name: name.trim(),
|
||||
phone: phone.trim() || null,
|
||||
address: address.trim() || null,
|
||||
logoUrl: logoUrl || null,
|
||||
slug: slug.trim() || undefined,
|
||||
});
|
||||
|
||||
if (updated.slug) {
|
||||
setSlug(updated.slug);
|
||||
await setActiveRestaurant({
|
||||
...active,
|
||||
slug: updated.slug,
|
||||
});
|
||||
}
|
||||
|
||||
Haptics.notificationAsync(Haptics.NotificationFeedbackType.Success).catch(() => {});
|
||||
Alert.alert("Başarılı 🎉", "Restoran bilgileri ve logo güncellendi.");
|
||||
Alert.alert("Başarılı 🎉", "Restoran bilgileri ve özel menü adresi güncellendi.");
|
||||
} catch (err) {
|
||||
Alert.alert("Hata", err instanceof Error ? err.message : "Güncellenemedi.");
|
||||
} finally {
|
||||
@@ -916,6 +926,46 @@ export default function AccountScreen() {
|
||||
/>
|
||||
</View>
|
||||
|
||||
{/* Restaurant Slug */}
|
||||
<View>
|
||||
<Text style={{ fontSize: 12, fontWeight: "700", color: "#78716C", marginBottom: 6 }}>
|
||||
Özel Menü Link Adresi (Slug)
|
||||
</Text>
|
||||
<View
|
||||
style={{
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
backgroundColor: "#FAF8F5",
|
||||
borderWidth: 1.5,
|
||||
borderColor: "#D6D3D1",
|
||||
borderRadius: 10,
|
||||
paddingHorizontal: 14,
|
||||
}}
|
||||
>
|
||||
<Text style={{ fontSize: 13, fontWeight: "700", color: "#C8A96B", marginRight: 4 }}>
|
||||
menul.io/
|
||||
</Text>
|
||||
<TextInput
|
||||
value={slug}
|
||||
onChangeText={(val) => setSlug(val.toLowerCase().replace(/[^a-z0-9-]/g, ""))}
|
||||
placeholder="kebapci-sinan"
|
||||
placeholderTextColor="#57534E"
|
||||
autoCapitalize="none"
|
||||
autoCorrect={false}
|
||||
style={{
|
||||
flex: 1,
|
||||
paddingVertical: 12,
|
||||
fontSize: 14,
|
||||
color: "#1C1917",
|
||||
fontWeight: "600",
|
||||
}}
|
||||
/>
|
||||
</View>
|
||||
<Text style={{ fontSize: 11, color: "#A8A29E", marginTop: 4 }}>
|
||||
Kullanıcılar <Text style={{ fontWeight: "700", color: "#78716C" }}>https://menul.io/{slug || "adresiniz"}</Text> üzerinden menünüze ulaşır.
|
||||
</Text>
|
||||
</View>
|
||||
|
||||
{/* Phone */}
|
||||
<View>
|
||||
<Text style={{ fontSize: 12, fontWeight: "700", color: "#78716C", marginBottom: 6 }}>
|
||||
|
||||
Reference in New Issue
Block a user