Changes
This commit is contained in:
@@ -7,6 +7,7 @@ import { AppLayout } from '@/components/AppLayout';
|
||||
import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '@/components/ui/card';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
import { Calendar } from '@/components/ui/calendar';
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
@@ -43,6 +44,10 @@ interface TimeSlot {
|
||||
available: boolean;
|
||||
}
|
||||
|
||||
interface Profile {
|
||||
whatsapp_number: string | null;
|
||||
}
|
||||
|
||||
export default function ConsultingBooking() {
|
||||
const { user, loading: authLoading } = useAuth();
|
||||
const navigate = useNavigate();
|
||||
@@ -52,11 +57,13 @@ export default function ConsultingBooking() {
|
||||
const [workhours, setWorkhours] = useState<Workhour[]>([]);
|
||||
const [confirmedSlots, setConfirmedSlots] = useState<ConfirmedSlot[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [profile, setProfile] = useState<Profile | null>(null);
|
||||
|
||||
const [selectedDate, setSelectedDate] = useState<Date | undefined>(addDays(new Date(), 1));
|
||||
const [selectedSlots, setSelectedSlots] = useState<string[]>([]);
|
||||
const [selectedCategory, setSelectedCategory] = useState('');
|
||||
const [notes, setNotes] = useState('');
|
||||
const [whatsappInput, setWhatsappInput] = useState('');
|
||||
const [submitting, setSubmitting] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -70,13 +77,15 @@ export default function ConsultingBooking() {
|
||||
}, [selectedDate]);
|
||||
|
||||
const fetchData = async () => {
|
||||
const [settingsRes, workhoursRes] = await Promise.all([
|
||||
const [settingsRes, workhoursRes, profileRes] = await Promise.all([
|
||||
supabase.from('consulting_settings').select('*').single(),
|
||||
supabase.from('workhours').select('*').order('weekday'),
|
||||
user ? supabase.from('profiles').select('whatsapp_number').eq('id', user.id).single() : Promise.resolve({ data: null }),
|
||||
]);
|
||||
|
||||
if (settingsRes.data) setSettings(settingsRes.data);
|
||||
if (workhoursRes.data) setWorkhours(workhoursRes.data);
|
||||
if (profileRes.data) setProfile(profileRes.data);
|
||||
setLoading(false);
|
||||
};
|
||||
|
||||
@@ -174,6 +183,15 @@ export default function ConsultingBooking() {
|
||||
setSubmitting(true);
|
||||
|
||||
try {
|
||||
// Save WhatsApp number if provided and not already saved
|
||||
if (whatsappInput && !profile?.whatsapp_number) {
|
||||
let normalized = whatsappInput.replace(/\D/g, '');
|
||||
if (normalized.startsWith('0')) normalized = '62' + normalized.substring(1);
|
||||
if (!normalized.startsWith('+')) normalized = '+' + normalized;
|
||||
|
||||
await supabase.from('profiles').update({ whatsapp_number: normalized }).eq('id', user.id);
|
||||
}
|
||||
|
||||
// Create order
|
||||
const { data: order, error: orderError } = await supabase
|
||||
.from('orders')
|
||||
@@ -348,13 +366,29 @@ export default function ConsultingBooking() {
|
||||
Catatan (Opsional)
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<CardContent className="space-y-4">
|
||||
<Textarea
|
||||
value={notes}
|
||||
onChange={(e) => setNotes(e.target.value)}
|
||||
placeholder="Jelaskan topik atau pertanyaan yang ingin dibahas..."
|
||||
className="border-2 min-h-[100px]"
|
||||
/>
|
||||
|
||||
{/* WhatsApp prompt if not saved */}
|
||||
{user && !profile?.whatsapp_number && (
|
||||
<div className="space-y-2 pt-2 border-t border-border">
|
||||
<Label className="text-sm">Nomor WhatsApp untuk pengingat sesi ini (opsional)</Label>
|
||||
<Input
|
||||
value={whatsappInput}
|
||||
onChange={(e) => setWhatsappInput(e.target.value)}
|
||||
placeholder="08123456789"
|
||||
className="border-2"
|
||||
/>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Akan otomatis tersimpan ke profil Anda
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
@@ -2,6 +2,7 @@ import { Link } from 'react-router-dom';
|
||||
import { Layout } from '@/components/Layout';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { useBranding } from '@/hooks/useBranding';
|
||||
import { TestimonialsSection } from '@/components/reviews/TestimonialsSection';
|
||||
import { ArrowRight, BookOpen, Video, Users, Star, Award, Target, Zap, Heart, Shield, Rocket } from 'lucide-react';
|
||||
|
||||
const iconMap: Record<string, React.ComponentType<{ className?: string }>> = {
|
||||
@@ -60,6 +61,8 @@ export default function Index() {
|
||||
})}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<TestimonialsSection />
|
||||
</Layout>
|
||||
);
|
||||
}
|
||||
|
||||
325
src/pages/admin/AdminReviews.tsx
Normal file
325
src/pages/admin/AdminReviews.tsx
Normal file
@@ -0,0 +1,325 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { supabase } from "@/integrations/supabase/client";
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from "@/components/ui/dialog";
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
||||
import { toast } from "@/hooks/use-toast";
|
||||
import { Star, Check, X, Edit, Trash2 } from "lucide-react";
|
||||
|
||||
interface Review {
|
||||
id: string;
|
||||
user_id: string;
|
||||
product_id: string | null;
|
||||
type: string;
|
||||
rating: number;
|
||||
title: string;
|
||||
body: string;
|
||||
is_approved: boolean;
|
||||
created_at: string;
|
||||
profiles: { full_name: string | null; email: string | null } | null;
|
||||
products: { title: string } | null;
|
||||
}
|
||||
|
||||
export default function AdminReviews() {
|
||||
const [reviews, setReviews] = useState<Review[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [filter, setFilter] = useState({ type: "all", status: "all" });
|
||||
const [editReview, setEditReview] = useState<Review | null>(null);
|
||||
const [editForm, setEditForm] = useState({ title: "", body: "" });
|
||||
|
||||
useEffect(() => {
|
||||
fetchReviews();
|
||||
}, []);
|
||||
|
||||
const fetchReviews = async () => {
|
||||
const { data, error } = await supabase
|
||||
.from("reviews")
|
||||
.select(`
|
||||
*,
|
||||
profiles (full_name, email),
|
||||
products (title)
|
||||
`)
|
||||
.order("created_at", { ascending: false });
|
||||
|
||||
if (error) {
|
||||
toast({ title: "Error", description: "Gagal mengambil data ulasan", variant: "destructive" });
|
||||
} else {
|
||||
setReviews((data as unknown as Review[]) || []);
|
||||
}
|
||||
setLoading(false);
|
||||
};
|
||||
|
||||
const handleApprove = async (id: string, approved: boolean) => {
|
||||
const { error } = await supabase
|
||||
.from("reviews")
|
||||
.update({ is_approved: approved })
|
||||
.eq("id", id);
|
||||
|
||||
if (error) {
|
||||
toast({ title: "Error", description: "Gagal mengubah status", variant: "destructive" });
|
||||
} else {
|
||||
toast({ title: "Berhasil", description: approved ? "Ulasan disetujui" : "Ulasan ditolak" });
|
||||
fetchReviews();
|
||||
}
|
||||
};
|
||||
|
||||
const handleDelete = async (id: string) => {
|
||||
if (!confirm("Hapus ulasan ini?")) return;
|
||||
|
||||
const { error } = await supabase.from("reviews").delete().eq("id", id);
|
||||
|
||||
if (error) {
|
||||
toast({ title: "Error", description: "Gagal menghapus", variant: "destructive" });
|
||||
} else {
|
||||
toast({ title: "Berhasil", description: "Ulasan dihapus" });
|
||||
fetchReviews();
|
||||
}
|
||||
};
|
||||
|
||||
const handleEdit = (review: Review) => {
|
||||
setEditReview(review);
|
||||
setEditForm({ title: review.title, body: review.body });
|
||||
};
|
||||
|
||||
const handleSaveEdit = async () => {
|
||||
if (!editReview) return;
|
||||
|
||||
const { error } = await supabase
|
||||
.from("reviews")
|
||||
.update({ title: editForm.title, body: editForm.body })
|
||||
.eq("id", editReview.id);
|
||||
|
||||
if (error) {
|
||||
toast({ title: "Error", description: "Gagal menyimpan", variant: "destructive" });
|
||||
} else {
|
||||
toast({ title: "Berhasil", description: "Ulasan diperbarui" });
|
||||
setEditReview(null);
|
||||
fetchReviews();
|
||||
}
|
||||
};
|
||||
|
||||
const filteredReviews = reviews.filter((r) => {
|
||||
if (filter.type !== "all" && r.type !== filter.type) return false;
|
||||
if (filter.status === "approved" && !r.is_approved) return false;
|
||||
if (filter.status === "pending" && r.is_approved) return false;
|
||||
return true;
|
||||
});
|
||||
|
||||
const renderStars = (rating: number) => (
|
||||
<div className="flex gap-0.5">
|
||||
{[1, 2, 3, 4, 5].map((i) => (
|
||||
<Star
|
||||
key={i}
|
||||
className={`w-4 h-4 ${i <= rating ? "fill-primary text-primary" : "text-muted-foreground"}`}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
|
||||
const getTypeLabel = (type: string) => {
|
||||
switch (type) {
|
||||
case "consulting": return "Konsultasi";
|
||||
case "bootcamp": return "Bootcamp";
|
||||
case "webinar": return "Webinar";
|
||||
case "general": return "Umum";
|
||||
default: return type;
|
||||
}
|
||||
};
|
||||
|
||||
if (loading) {
|
||||
return <div className="p-6">Loading...</div>;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div>
|
||||
<h1 className="text-3xl font-bold">Ulasan</h1>
|
||||
<p className="text-muted-foreground">Kelola ulasan dari member</p>
|
||||
</div>
|
||||
|
||||
<div className="flex gap-4">
|
||||
<Select value={filter.type} onValueChange={(v) => setFilter({ ...filter, type: v })}>
|
||||
<SelectTrigger className="w-40 border-2">
|
||||
<SelectValue placeholder="Tipe" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="all">Semua Tipe</SelectItem>
|
||||
<SelectItem value="consulting">Konsultasi</SelectItem>
|
||||
<SelectItem value="bootcamp">Bootcamp</SelectItem>
|
||||
<SelectItem value="webinar">Webinar</SelectItem>
|
||||
<SelectItem value="general">Umum</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
|
||||
<Select value={filter.status} onValueChange={(v) => setFilter({ ...filter, status: v })}>
|
||||
<SelectTrigger className="w-40 border-2">
|
||||
<SelectValue placeholder="Status" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="all">Semua Status</SelectItem>
|
||||
<SelectItem value="pending">Menunggu</SelectItem>
|
||||
<SelectItem value="approved">Disetujui</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
<Tabs defaultValue="list">
|
||||
<TabsList>
|
||||
<TabsTrigger value="list">Daftar ({filteredReviews.length})</TabsTrigger>
|
||||
<TabsTrigger value="pending">
|
||||
Menunggu ({reviews.filter((r) => !r.is_approved).length})
|
||||
</TabsTrigger>
|
||||
</TabsList>
|
||||
|
||||
<TabsContent value="list" className="mt-4">
|
||||
<div className="space-y-4">
|
||||
{filteredReviews.length === 0 ? (
|
||||
<Card className="border-2 border-border">
|
||||
<CardContent className="py-8 text-center text-muted-foreground">
|
||||
Tidak ada ulasan
|
||||
</CardContent>
|
||||
</Card>
|
||||
) : (
|
||||
filteredReviews.map((review) => (
|
||||
<Card key={review.id} className="border-2 border-border">
|
||||
<CardContent className="py-4">
|
||||
<div className="flex items-start justify-between gap-4">
|
||||
<div className="flex-1 space-y-2">
|
||||
<div className="flex items-center gap-2 flex-wrap">
|
||||
{renderStars(review.rating)}
|
||||
<Badge variant="outline">{getTypeLabel(review.type)}</Badge>
|
||||
<Badge className={review.is_approved ? "bg-accent" : "bg-secondary"}>
|
||||
{review.is_approved ? "Disetujui" : "Menunggu"}
|
||||
</Badge>
|
||||
</div>
|
||||
<h3 className="font-bold">{review.title}</h3>
|
||||
<p className="text-muted-foreground text-sm">{review.body}</p>
|
||||
<div className="text-xs text-muted-foreground">
|
||||
<span>{review.profiles?.full_name || review.profiles?.email || "Unknown"}</span>
|
||||
{review.products && <span> • {review.products.title}</span>}
|
||||
<span> • {new Date(review.created_at).toLocaleDateString("id-ID")}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
{!review.is_approved && (
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
className="border-2"
|
||||
onClick={() => handleApprove(review.id, true)}
|
||||
>
|
||||
<Check className="w-4 h-4" />
|
||||
</Button>
|
||||
)}
|
||||
{review.is_approved && (
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
className="border-2"
|
||||
onClick={() => handleApprove(review.id, false)}
|
||||
>
|
||||
<X className="w-4 h-4" />
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
className="border-2"
|
||||
onClick={() => handleEdit(review)}
|
||||
>
|
||||
<Edit className="w-4 h-4" />
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
className="border-2 text-destructive hover:text-destructive"
|
||||
onClick={() => handleDelete(review.id)}
|
||||
>
|
||||
<Trash2 className="w-4 h-4" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
</TabsContent>
|
||||
|
||||
<TabsContent value="pending" className="mt-4">
|
||||
<div className="space-y-4">
|
||||
{reviews.filter((r) => !r.is_approved).map((review) => (
|
||||
<Card key={review.id} className="border-2 border-primary/20">
|
||||
<CardContent className="py-4">
|
||||
<div className="flex items-start justify-between gap-4">
|
||||
<div className="flex-1 space-y-2">
|
||||
<div className="flex items-center gap-2">
|
||||
{renderStars(review.rating)}
|
||||
<Badge variant="outline">{getTypeLabel(review.type)}</Badge>
|
||||
</div>
|
||||
<h3 className="font-bold">{review.title}</h3>
|
||||
<p className="text-muted-foreground text-sm">{review.body}</p>
|
||||
<div className="text-xs text-muted-foreground">
|
||||
{review.profiles?.full_name || review.profiles?.email}
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
<Button size="sm" onClick={() => handleApprove(review.id, true)}>
|
||||
<Check className="w-4 h-4 mr-1" /> Setujui
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
className="border-2 text-destructive"
|
||||
onClick={() => handleDelete(review.id)}
|
||||
>
|
||||
<Trash2 className="w-4 h-4" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
|
||||
<Dialog open={!!editReview} onOpenChange={() => setEditReview(null)}>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>Edit Ulasan</DialogTitle>
|
||||
</DialogHeader>
|
||||
<div className="space-y-4">
|
||||
<div className="space-y-2">
|
||||
<label className="text-sm font-medium">Judul</label>
|
||||
<Input
|
||||
value={editForm.title}
|
||||
onChange={(e) => setEditForm({ ...editForm, title: e.target.value })}
|
||||
className="border-2"
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<label className="text-sm font-medium">Isi</label>
|
||||
<Textarea
|
||||
value={editForm.body}
|
||||
onChange={(e) => setEditForm({ ...editForm, body: e.target.value })}
|
||||
className="border-2 min-h-[100px]"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<Button variant="outline" onClick={() => setEditReview(null)}>
|
||||
Batal
|
||||
</Button>
|
||||
<Button onClick={handleSaveEdit}>Simpan</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import { Button } from "@/components/ui/button";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { formatIDR } from "@/lib/format";
|
||||
import { Video, Calendar, BookOpen, ArrowRight, Package, Receipt, ShoppingBag } from "lucide-react";
|
||||
import { WhatsAppBanner } from "@/components/WhatsAppBanner";
|
||||
|
||||
interface UserAccess {
|
||||
id: string;
|
||||
@@ -35,6 +36,7 @@ export default function MemberDashboard() {
|
||||
const [access, setAccess] = useState<UserAccess[]>([]);
|
||||
const [recentOrders, setRecentOrders] = useState<Order[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [hasWhatsApp, setHasWhatsApp] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
if (!authLoading && !user) navigate("/auth");
|
||||
@@ -42,7 +44,7 @@ export default function MemberDashboard() {
|
||||
}, [user, authLoading]);
|
||||
|
||||
const fetchData = async () => {
|
||||
const [accessRes, ordersRes, paidOrdersRes] = await Promise.all([
|
||||
const [accessRes, ordersRes, paidOrdersRes, profileRes] = await Promise.all([
|
||||
supabase
|
||||
.from("user_access")
|
||||
.select(`id, product:products (id, title, slug, type, meeting_link, recording_url)`)
|
||||
@@ -61,6 +63,7 @@ export default function MemberDashboard() {
|
||||
.eq("user_id", user!.id)
|
||||
.eq("payment_status", "paid")
|
||||
.eq("payment_provider", "pakasir"),
|
||||
supabase.from("profiles").select("whatsapp_number").eq("id", user!.id).single(),
|
||||
]);
|
||||
|
||||
// Combine access from user_access and paid orders
|
||||
@@ -81,6 +84,7 @@ export default function MemberDashboard() {
|
||||
|
||||
setAccess([...directAccess, ...paidProductAccess]);
|
||||
if (ordersRes.data) setRecentOrders(ordersRes.data);
|
||||
if (profileRes.data) setHasWhatsApp(!!profileRes.data.whatsapp_number);
|
||||
setLoading(false);
|
||||
};
|
||||
|
||||
@@ -118,6 +122,8 @@ export default function MemberDashboard() {
|
||||
<h1 className="text-4xl font-bold mb-2">Dashboard</h1>
|
||||
<p className="text-muted-foreground mb-8">Selamat datang kembali!</p>
|
||||
|
||||
{!hasWhatsApp && <WhatsAppBanner />}
|
||||
|
||||
<div className="grid gap-6 md:grid-cols-2 lg:grid-cols-3 mb-8">
|
||||
<Card className="border-2 border-border">
|
||||
<CardContent className="pt-6">
|
||||
|
||||
@@ -7,15 +7,18 @@ import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Switch } from '@/components/ui/switch';
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
import { toast } from '@/hooks/use-toast';
|
||||
import { User, LogOut } from 'lucide-react';
|
||||
import { User, LogOut, Phone } from 'lucide-react';
|
||||
|
||||
interface Profile {
|
||||
id: string;
|
||||
email: string | null;
|
||||
full_name: string | null;
|
||||
avatar_url: string | null;
|
||||
whatsapp_number: string | null;
|
||||
whatsapp_opt_in: boolean;
|
||||
}
|
||||
|
||||
export default function MemberProfile() {
|
||||
@@ -24,7 +27,12 @@ export default function MemberProfile() {
|
||||
const [profile, setProfile] = useState<Profile | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [form, setForm] = useState({ full_name: '', avatar_url: '' });
|
||||
const [form, setForm] = useState({
|
||||
full_name: '',
|
||||
avatar_url: '',
|
||||
whatsapp_number: '',
|
||||
whatsapp_opt_in: false,
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (!authLoading && !user) navigate('/auth');
|
||||
@@ -39,16 +47,42 @@ export default function MemberProfile() {
|
||||
.single();
|
||||
if (data) {
|
||||
setProfile(data);
|
||||
setForm({ full_name: data.full_name || '', avatar_url: data.avatar_url || '' });
|
||||
setForm({
|
||||
full_name: data.full_name || '',
|
||||
avatar_url: data.avatar_url || '',
|
||||
whatsapp_number: data.whatsapp_number || '',
|
||||
whatsapp_opt_in: data.whatsapp_opt_in || false,
|
||||
});
|
||||
}
|
||||
setLoading(false);
|
||||
};
|
||||
|
||||
const normalizeWhatsApp = (number: string) => {
|
||||
// Remove all non-digits
|
||||
let cleaned = number.replace(/\D/g, '');
|
||||
// Convert 08xx to +628xx
|
||||
if (cleaned.startsWith('0')) {
|
||||
cleaned = '62' + cleaned.substring(1);
|
||||
}
|
||||
// Add + if not present
|
||||
if (cleaned && !cleaned.startsWith('+')) {
|
||||
cleaned = '+' + cleaned;
|
||||
}
|
||||
return cleaned;
|
||||
};
|
||||
|
||||
const handleSave = async () => {
|
||||
setSaving(true);
|
||||
const normalizedWA = normalizeWhatsApp(form.whatsapp_number);
|
||||
|
||||
const { error } = await supabase
|
||||
.from('profiles')
|
||||
.update({ full_name: form.full_name, avatar_url: form.avatar_url || null })
|
||||
.update({
|
||||
full_name: form.full_name,
|
||||
avatar_url: form.avatar_url || null,
|
||||
whatsapp_number: normalizedWA || null,
|
||||
whatsapp_opt_in: form.whatsapp_opt_in,
|
||||
})
|
||||
.eq('id', user!.id);
|
||||
|
||||
if (error) {
|
||||
@@ -113,12 +147,48 @@ export default function MemberProfile() {
|
||||
placeholder="https://..."
|
||||
/>
|
||||
</div>
|
||||
<Button onClick={handleSave} disabled={saving} className="w-full shadow-sm">
|
||||
{saving ? 'Menyimpan...' : 'Simpan Profil'}
|
||||
</Button>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card className="border-2 border-border">
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center gap-2">
|
||||
<Phone className="w-5 h-5" />
|
||||
WhatsApp
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-4">
|
||||
<div className="space-y-2">
|
||||
<Label>Nomor WhatsApp</Label>
|
||||
<Input
|
||||
value={form.whatsapp_number}
|
||||
onChange={(e) => setForm({ ...form, whatsapp_number: e.target.value })}
|
||||
className="border-2"
|
||||
placeholder="08123456789"
|
||||
/>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Akan dinormalisasi ke format +62xxx
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="space-y-0.5">
|
||||
<Label>Ijinkan pengingat via WhatsApp</Label>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Terima notifikasi konsultasi & bootcamp
|
||||
</p>
|
||||
</div>
|
||||
<Switch
|
||||
checked={form.whatsapp_opt_in}
|
||||
onCheckedChange={(checked) => setForm({ ...form, whatsapp_opt_in: checked })}
|
||||
/>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Button onClick={handleSave} disabled={saving} className="w-full shadow-sm">
|
||||
{saving ? 'Menyimpan...' : 'Simpan Profil'}
|
||||
</Button>
|
||||
|
||||
<Card className="border-2 border-border">
|
||||
<CardContent className="pt-6">
|
||||
<Button variant="outline" onClick={handleSignOut} className="w-full border-2 text-destructive hover:text-destructive">
|
||||
|
||||
@@ -15,11 +15,12 @@ interface OrderItem {
|
||||
id: string;
|
||||
product_id: string;
|
||||
quantity: number;
|
||||
price: number;
|
||||
products: {
|
||||
title: string;
|
||||
type: string;
|
||||
slug: string;
|
||||
price: number;
|
||||
sale_price: number | null;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -72,8 +73,7 @@ export default function OrderDetail() {
|
||||
id,
|
||||
product_id,
|
||||
quantity,
|
||||
price,
|
||||
products (title, type, slug)
|
||||
products (title, type, slug, price, sale_price)
|
||||
)
|
||||
`)
|
||||
.eq("id", id)
|
||||
@@ -279,7 +279,7 @@ export default function OrderDetail() {
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<p className="font-medium">{formatIDR(item.price)}</p>
|
||||
<p className="font-medium">{formatIDR(item.products.sale_price || item.products.price)}</p>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user