feat: desktop image thumbnails, gallery lightbox portal, client-side compression, clickable table rows, fix header gap
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { MoreHorizontal, Plus, Pencil, Trash2, CheckCircle } from "lucide-react";
|
||||
import { useState, useEffect } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { DotsThree, Plus, PencilSimple, Trash, CheckCircle, List, CalendarDots } from '@/lib/icons';
|
||||
import { toast } from "sonner";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
@@ -17,9 +18,13 @@ import {
|
||||
deleteActivityAction,
|
||||
} from "@/lib/appwrite/activity-actions";
|
||||
import { ActivityFormSheet } from "./activity-form-sheet";
|
||||
import { ActivityCalendar } from "./activity-calendar";
|
||||
import { DeleteConfirmDialog } from "@/components/ui/delete-confirm-dialog";
|
||||
import type { Activity, Customer, Property } from "@/lib/appwrite/schema";
|
||||
import { ACTIVITY_TYPE_LABELS } from "@/lib/appwrite/schema";
|
||||
|
||||
type ViewMode = "list" | "calendar";
|
||||
|
||||
interface ActivitiesClientProps {
|
||||
initialActivities: Activity[];
|
||||
customers: Customer[];
|
||||
@@ -31,9 +36,12 @@ export function ActivitiesClient({
|
||||
customers,
|
||||
properties,
|
||||
}: ActivitiesClientProps) {
|
||||
const router = useRouter();
|
||||
const [activities, setActivities] = useState(initialActivities);
|
||||
const [sheetOpen, setSheetOpen] = useState(false);
|
||||
const [editing, setEditing] = useState<Activity | null>(null);
|
||||
const [deleteTarget, setDeleteTarget] = useState<Activity | null>(null);
|
||||
const [viewMode, setViewMode] = useState<ViewMode>("list");
|
||||
|
||||
function customerName(id?: string | null) {
|
||||
if (!id) return "—";
|
||||
@@ -45,15 +53,19 @@ export function ActivitiesClient({
|
||||
return properties.find((p) => p.$id === id)?.title ?? "—";
|
||||
}
|
||||
|
||||
function openCreate() {
|
||||
setEditing(null);
|
||||
setSheetOpen(true);
|
||||
}
|
||||
useEffect(() => {
|
||||
const open = () => { setEditing(null); setSheetOpen(true); };
|
||||
const close = () => setSheetOpen(false);
|
||||
window.addEventListener("kovak:open-form-activities", open);
|
||||
window.addEventListener("kovak:close-form-activities", close);
|
||||
return () => {
|
||||
window.removeEventListener("kovak:open-form-activities", open);
|
||||
window.removeEventListener("kovak:close-form-activities", close);
|
||||
};
|
||||
}, []);
|
||||
|
||||
function openEdit(a: Activity) {
|
||||
setEditing(a);
|
||||
setSheetOpen(true);
|
||||
}
|
||||
function openCreate() { setEditing(null); setSheetOpen(true); }
|
||||
function openEdit(a: Activity) { setEditing(a); setSheetOpen(true); }
|
||||
|
||||
async function handleComplete(a: Activity) {
|
||||
const result = await completeActivityAction(a.$id);
|
||||
@@ -67,11 +79,12 @@ export function ActivitiesClient({
|
||||
}
|
||||
}
|
||||
|
||||
async function handleDelete(a: Activity) {
|
||||
if (!confirm("Bu aktivite silinsin mi?")) return;
|
||||
const result = await deleteActivityAction(a.$id);
|
||||
async function doDelete() {
|
||||
if (!deleteTarget) return;
|
||||
const result = await deleteActivityAction(deleteTarget.$id);
|
||||
if (result.ok) {
|
||||
setActivities((prev) => prev.filter((x) => x.$id !== a.$id));
|
||||
setActivities((prev) => prev.filter((x) => x.$id !== deleteTarget.$id));
|
||||
setDeleteTarget(null);
|
||||
toast.success("Aktivite silindi.");
|
||||
} else {
|
||||
toast.error(result.error ?? "Silinemedi.");
|
||||
@@ -80,15 +93,57 @@ export function ActivitiesClient({
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center justify-between gap-3 flex-wrap">
|
||||
<h1 className="text-2xl font-bold">Aktiviteler</h1>
|
||||
<Button onClick={openCreate} size="sm">
|
||||
<Plus className="mr-1.5 size-4" />
|
||||
Yeni Aktivite
|
||||
</Button>
|
||||
<div className="flex items-center gap-2">
|
||||
{/* View toggle */}
|
||||
<div className="flex rounded-md border overflow-hidden">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setViewMode("list")}
|
||||
className={`flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium transition-colors ${
|
||||
viewMode === "list"
|
||||
? "bg-primary text-primary-foreground"
|
||||
: "bg-background text-muted-foreground hover:text-foreground"
|
||||
}`}
|
||||
>
|
||||
<List className="size-3.5" />
|
||||
Liste
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setViewMode("calendar")}
|
||||
className={`flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium transition-colors ${
|
||||
viewMode === "calendar"
|
||||
? "bg-primary text-primary-foreground"
|
||||
: "bg-background text-muted-foreground hover:text-foreground"
|
||||
}`}
|
||||
>
|
||||
<CalendarDots className="size-3.5" />
|
||||
Takvim
|
||||
</button>
|
||||
</div>
|
||||
<Button onClick={openCreate} size="sm" data-tour="activities-add">
|
||||
<Plus className="mr-1.5 size-4" />
|
||||
Yeni Aktivite
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="rounded-md border">
|
||||
{/* Calendar view */}
|
||||
{viewMode === "calendar" && (
|
||||
<ActivityCalendar
|
||||
activities={activities}
|
||||
customers={customers}
|
||||
properties={properties}
|
||||
onEdit={openEdit}
|
||||
onComplete={handleComplete}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* List view */}
|
||||
{viewMode === "list" && (
|
||||
<div data-tour="activities-table" className="rounded-md border">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
@@ -133,7 +188,7 @@ export function ActivitiesClient({
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" size="icon" className="size-8">
|
||||
<MoreHorizontal className="size-4" />
|
||||
<DotsThree className="size-4" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
@@ -144,14 +199,14 @@ export function ActivitiesClient({
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
<DropdownMenuItem onClick={() => openEdit(a)}>
|
||||
<Pencil className="mr-2 size-4" />
|
||||
<PencilSimple className="mr-2 size-4" />
|
||||
Düzenle
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem
|
||||
onClick={() => handleDelete(a)}
|
||||
onClick={() => setDeleteTarget(a)}
|
||||
className="text-destructive focus:text-destructive"
|
||||
>
|
||||
<Trash2 className="mr-2 size-4" />
|
||||
<Trash className="mr-2 size-4" />
|
||||
Sil
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
@@ -162,6 +217,7 @@ export function ActivitiesClient({
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<ActivityFormSheet
|
||||
open={sheetOpen}
|
||||
@@ -169,6 +225,14 @@ export function ActivitiesClient({
|
||||
activity={editing}
|
||||
customers={customers}
|
||||
properties={properties}
|
||||
onSuccess={() => router.refresh()}
|
||||
/>
|
||||
<DeleteConfirmDialog
|
||||
open={!!deleteTarget}
|
||||
onOpenChange={(v) => { if (!v) setDeleteTarget(null); }}
|
||||
title="Bu aktivite silinsin mi?"
|
||||
description="Bu aktivite kalıcı olarak silinecek ve geri alınamaz."
|
||||
onConfirm={doDelete}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -0,0 +1,320 @@
|
||||
"use client";
|
||||
|
||||
import { useState, useMemo } from "react";
|
||||
import { CaretLeft, CaretRight, CheckCircle, PencilSimple, Clock, User, Buildings } from '@/lib/icons';
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import type { Activity, Customer, Property } from "@/lib/appwrite/schema";
|
||||
import { ACTIVITY_TYPE_LABELS } from "@/lib/appwrite/schema";
|
||||
|
||||
const DAYS = ["Pzt", "Sal", "Çar", "Per", "Cum", "Cmt", "Paz"];
|
||||
const MONTHS = [
|
||||
"Ocak", "Şubat", "Mart", "Nisan", "Mayıs", "Haziran",
|
||||
"Temmuz", "Ağustos", "Eylül", "Ekim", "Kasım", "Aralık",
|
||||
];
|
||||
|
||||
const TYPE_COLORS: Record<string, string> = {
|
||||
gorusme: "bg-blue-500",
|
||||
teklif: "bg-amber-500",
|
||||
ziyaret: "bg-emerald-500",
|
||||
arama: "bg-purple-500",
|
||||
not: "bg-gray-400",
|
||||
};
|
||||
|
||||
const TYPE_BADGE_COLORS: Record<string, string> = {
|
||||
gorusme: "bg-blue-100 text-blue-700 dark:bg-blue-900/40 dark:text-blue-300",
|
||||
teklif: "bg-amber-100 text-amber-700 dark:bg-amber-900/40 dark:text-amber-300",
|
||||
ziyaret: "bg-emerald-100 text-emerald-700 dark:bg-emerald-900/40 dark:text-emerald-300",
|
||||
arama: "bg-purple-100 text-purple-700 dark:bg-purple-900/40 dark:text-purple-300",
|
||||
not: "bg-gray-100 text-gray-600 dark:bg-gray-800 dark:text-gray-300",
|
||||
};
|
||||
|
||||
function toDateKey(date: Date): string {
|
||||
return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}-${String(date.getDate()).padStart(2, "0")}`;
|
||||
}
|
||||
|
||||
function activityDateKey(a: Activity): string | null {
|
||||
if (!a.dueDate) return null;
|
||||
const d = new Date(a.dueDate);
|
||||
if (isNaN(d.getTime())) return null;
|
||||
return toDateKey(d);
|
||||
}
|
||||
|
||||
interface Props {
|
||||
activities: Activity[];
|
||||
customers: Customer[];
|
||||
properties: Property[];
|
||||
onEdit: (a: Activity) => void;
|
||||
onComplete: (a: Activity) => void;
|
||||
}
|
||||
|
||||
export function ActivityCalendar({ activities, customers, properties, onEdit, onComplete }: Props) {
|
||||
const today = new Date();
|
||||
const [year, setYear] = useState(today.getFullYear());
|
||||
const [month, setMonth] = useState(today.getMonth());
|
||||
const [selectedKey, setSelectedKey] = useState<string | null>(toDateKey(today));
|
||||
|
||||
function prevMonth() {
|
||||
if (month === 0) { setMonth(11); setYear(y => y - 1); }
|
||||
else setMonth(m => m - 1);
|
||||
}
|
||||
function nextMonth() {
|
||||
if (month === 11) { setMonth(0); setYear(y => y + 1); }
|
||||
else setMonth(m => m + 1);
|
||||
}
|
||||
|
||||
// Index activities by date key
|
||||
const byDate = useMemo(() => {
|
||||
const map: Record<string, Activity[]> = {};
|
||||
for (const a of activities) {
|
||||
const key = activityDateKey(a);
|
||||
if (!key) continue;
|
||||
if (!map[key]) map[key] = [];
|
||||
map[key].push(a);
|
||||
}
|
||||
return map;
|
||||
}, [activities]);
|
||||
|
||||
// Build calendar grid
|
||||
const cells = useMemo(() => {
|
||||
const firstDay = new Date(year, month, 1);
|
||||
// Monday-based: 0=Mon … 6=Sun
|
||||
let startOffset = firstDay.getDay() - 1;
|
||||
if (startOffset < 0) startOffset = 6;
|
||||
|
||||
const daysInMonth = new Date(year, month + 1, 0).getDate();
|
||||
const totalCells = Math.ceil((startOffset + daysInMonth) / 7) * 7;
|
||||
|
||||
const result: Array<{ date: Date | null; key: string | null }> = [];
|
||||
for (let i = 0; i < totalCells; i++) {
|
||||
const dayNum = i - startOffset + 1;
|
||||
if (dayNum < 1 || dayNum > daysInMonth) {
|
||||
result.push({ date: null, key: null });
|
||||
} else {
|
||||
const d = new Date(year, month, dayNum);
|
||||
result.push({ date: d, key: toDateKey(d) });
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}, [year, month]);
|
||||
|
||||
const selectedActivities = selectedKey ? (byDate[selectedKey] ?? []) : [];
|
||||
const selectedDate = selectedKey ? new Date(selectedKey + "T12:00:00") : null;
|
||||
|
||||
function customerName(id?: string | null) {
|
||||
if (!id) return null;
|
||||
return customers.find((c) => c.$id === id)?.name ?? null;
|
||||
}
|
||||
function propertyTitle(id?: string | null) {
|
||||
if (!id) return null;
|
||||
return properties.find((p) => p.$id === id)?.title ?? null;
|
||||
}
|
||||
|
||||
const todayKey = toDateKey(today);
|
||||
|
||||
return (
|
||||
<div className="flex flex-col lg:flex-row gap-4 min-h-0">
|
||||
{/* === Calendar Grid === */}
|
||||
<div className="flex-1 min-w-0">
|
||||
{/* Month nav */}
|
||||
<div className="flex items-center justify-between mb-3">
|
||||
<Button variant="ghost" size="icon" onClick={prevMonth} className="size-8">
|
||||
<CaretLeft className="size-4" />
|
||||
</Button>
|
||||
<span className="font-semibold text-base">
|
||||
{MONTHS[month]} {year}
|
||||
</span>
|
||||
<Button variant="ghost" size="icon" onClick={nextMonth} className="size-8">
|
||||
<CaretRight className="size-4" />
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* Day headers */}
|
||||
<div className="grid grid-cols-7 mb-1">
|
||||
{DAYS.map((d) => (
|
||||
<div key={d} className="text-center text-xs text-muted-foreground py-1 font-medium">
|
||||
{d}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* Day cells */}
|
||||
<div className="grid grid-cols-7 gap-px bg-border rounded-lg overflow-hidden border">
|
||||
{cells.map((cell, i) => {
|
||||
if (!cell.date || !cell.key) {
|
||||
return <div key={i} className="bg-muted/40 min-h-[72px]" />;
|
||||
}
|
||||
const cellActivities = byDate[cell.key] ?? [];
|
||||
const isToday = cell.key === todayKey;
|
||||
const isSelected = cell.key === selectedKey;
|
||||
const visible = cellActivities.slice(0, 3);
|
||||
const overflow = cellActivities.length - 3;
|
||||
|
||||
return (
|
||||
<button
|
||||
key={cell.key}
|
||||
type="button"
|
||||
onClick={() => setSelectedKey(cell.key)}
|
||||
className={`bg-background min-h-[72px] p-1.5 text-left transition-colors hover:bg-muted/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring ${
|
||||
isSelected ? "ring-2 ring-inset ring-primary" : ""
|
||||
}`}
|
||||
>
|
||||
<span
|
||||
className={`text-xs font-medium inline-flex size-5 items-center justify-center rounded-full mb-1 ${
|
||||
isToday
|
||||
? "bg-primary text-primary-foreground"
|
||||
: "text-foreground"
|
||||
}`}
|
||||
>
|
||||
{cell.date.getDate()}
|
||||
</span>
|
||||
<div className="flex flex-col gap-px">
|
||||
{visible.map((a) => (
|
||||
<div
|
||||
key={a.$id}
|
||||
className={`text-[10px] leading-4 rounded px-1 truncate text-white ${TYPE_COLORS[a.type] ?? "bg-gray-400"} ${
|
||||
a.completedAt ? "opacity-50" : ""
|
||||
}`}
|
||||
>
|
||||
{a.title}
|
||||
</div>
|
||||
))}
|
||||
{overflow > 0 && (
|
||||
<div className="text-[10px] text-muted-foreground pl-1">+{overflow} daha</div>
|
||||
)}
|
||||
</div>
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
|
||||
{/* Legend */}
|
||||
<div className="flex flex-wrap gap-3 mt-3 text-xs text-muted-foreground">
|
||||
{Object.entries(ACTIVITY_TYPE_LABELS).map(([key, label]) => (
|
||||
<div key={key} className="flex items-center gap-1">
|
||||
<span className={`inline-block size-2 rounded-full ${TYPE_COLORS[key]}`} />
|
||||
{label}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* === Day Panel === */}
|
||||
<div className="w-full lg:w-72 xl:w-80 shrink-0">
|
||||
<div className="rounded-lg border h-full flex flex-col">
|
||||
{/* Panel header */}
|
||||
<div className="px-4 py-3 border-b">
|
||||
{selectedDate ? (
|
||||
<div>
|
||||
<p className="font-semibold text-sm">
|
||||
{selectedDate.toLocaleDateString("tr-TR", { weekday: "long", day: "numeric", month: "long" })}
|
||||
</p>
|
||||
<p className="text-xs text-muted-foreground mt-0.5">
|
||||
{selectedActivities.length === 0
|
||||
? "Bu gün için aktivite yok"
|
||||
: `${selectedActivities.length} aktivite`}
|
||||
</p>
|
||||
</div>
|
||||
) : (
|
||||
<p className="text-sm text-muted-foreground">Gün seçin</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Activity list */}
|
||||
<div className="flex-1 overflow-y-auto">
|
||||
{selectedActivities.length === 0 ? (
|
||||
<div className="flex flex-col items-center justify-center h-32 text-muted-foreground text-sm">
|
||||
<Clock className="size-8 mb-2 opacity-30" />
|
||||
<span>Aktivite bulunmuyor</span>
|
||||
</div>
|
||||
) : (
|
||||
<div className="divide-y">
|
||||
{selectedActivities.map((a) => (
|
||||
<ActivityCard
|
||||
key={a.$id}
|
||||
activity={a}
|
||||
customerName={customerName(a.customerId)}
|
||||
propertyTitle={propertyTitle(a.propertyId)}
|
||||
onEdit={onEdit}
|
||||
onComplete={onComplete}
|
||||
typeBadgeColor={TYPE_BADGE_COLORS[a.type] ?? TYPE_BADGE_COLORS.not}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
interface CardProps {
|
||||
activity: Activity;
|
||||
customerName: string | null;
|
||||
propertyTitle: string | null;
|
||||
typeBadgeColor: string;
|
||||
onEdit: (a: Activity) => void;
|
||||
onComplete: (a: Activity) => void;
|
||||
}
|
||||
|
||||
function ActivityCard({ activity: a, customerName, propertyTitle, typeBadgeColor, onEdit, onComplete }: CardProps) {
|
||||
return (
|
||||
<div className={`px-4 py-3 hover:bg-muted/40 transition-colors ${a.completedAt ? "opacity-60" : ""}`}>
|
||||
<div className="flex items-start justify-between gap-2 mb-1.5">
|
||||
<span className={`inline-flex text-[10px] font-medium px-1.5 py-0.5 rounded-full ${typeBadgeColor}`}>
|
||||
{ACTIVITY_TYPE_LABELS[a.type] ?? a.type}
|
||||
</span>
|
||||
{a.completedAt ? (
|
||||
<Badge variant="secondary" className="text-[10px] h-4 px-1.5">Tamam</Badge>
|
||||
) : (
|
||||
<Badge className="text-[10px] h-4 px-1.5">Açık</Badge>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<p className="text-sm font-medium leading-tight mb-1.5">{a.title}</p>
|
||||
|
||||
{a.description && (
|
||||
<p className="text-xs text-muted-foreground line-clamp-2 mb-1.5">{a.description}</p>
|
||||
)}
|
||||
|
||||
<div className="flex flex-col gap-0.5 mb-2">
|
||||
{customerName && (
|
||||
<div className="flex items-center gap-1 text-xs text-muted-foreground">
|
||||
<User className="size-3 shrink-0" />
|
||||
<span className="truncate">{customerName}</span>
|
||||
</div>
|
||||
)}
|
||||
{propertyTitle && (
|
||||
<div className="flex items-center gap-1 text-xs text-muted-foreground">
|
||||
<Buildings className="size-3 shrink-0" />
|
||||
<span className="truncate">{propertyTitle}</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="flex gap-1.5">
|
||||
{!a.completedAt && (
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="h-6 text-xs px-2 flex-1"
|
||||
onClick={() => onComplete(a)}
|
||||
>
|
||||
<CheckCircle className="size-3 mr-1" />
|
||||
Tamamla
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="h-6 text-xs px-2 flex-1"
|
||||
onClick={() => onEdit(a)}
|
||||
>
|
||||
<PencilSimple className="size-3 mr-1" />
|
||||
Düzenle
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,20 +1,12 @@
|
||||
"use client";
|
||||
|
||||
import { useActionState, useEffect } from "react";
|
||||
import { Loader2 } from "lucide-react";
|
||||
import { toast } from "sonner";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import {
|
||||
Sheet,
|
||||
SheetContent,
|
||||
SheetFooter,
|
||||
SheetHeader,
|
||||
SheetTitle,
|
||||
} from "@/components/ui/sheet";
|
||||
import { ResponsiveSheet, FormWizard } from "@/components/ui/responsive-sheet";
|
||||
import { createActivityAction, updateActivityAction } from "@/lib/appwrite/activity-actions";
|
||||
import type { Activity, Customer, Property } from "@/lib/appwrite/schema";
|
||||
|
||||
@@ -30,18 +22,8 @@ interface ActivityFormSheetProps {
|
||||
onSuccess?: () => void;
|
||||
}
|
||||
|
||||
export function ActivityFormSheet({
|
||||
open,
|
||||
onOpenChange,
|
||||
activity,
|
||||
customers,
|
||||
properties,
|
||||
onSuccess,
|
||||
}: ActivityFormSheetProps) {
|
||||
const action = activity
|
||||
? updateActivityAction.bind(null, activity.$id)
|
||||
: createActivityAction;
|
||||
|
||||
export function ActivityFormSheet({ open, onOpenChange, activity, customers, properties, onSuccess }: ActivityFormSheetProps) {
|
||||
const action = activity ? updateActivityAction.bind(null, activity.$id) : createActivityAction;
|
||||
const [state, formAction, isPending] = useActionState(action, INITIAL);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -56,86 +38,82 @@ export function ActivityFormSheet({
|
||||
|
||||
const fe = state.fieldErrors ?? {};
|
||||
|
||||
return (
|
||||
<Sheet open={open} onOpenChange={onOpenChange}>
|
||||
<SheetContent className="sm:max-w-md">
|
||||
<SheetHeader>
|
||||
<SheetTitle>{activity ? "Aktiviteyi Düzenle" : "Yeni Aktivite"}</SheetTitle>
|
||||
</SheetHeader>
|
||||
|
||||
<form action={formAction} className="mt-4 space-y-4 pb-6">
|
||||
<div className="grid gap-1.5">
|
||||
<Label>Tip *</Label>
|
||||
<select
|
||||
name="type"
|
||||
defaultValue={activity?.type ?? "gorusme"}
|
||||
className="border-input bg-background h-9 rounded-md border px-3 text-sm"
|
||||
>
|
||||
<option value="gorusme">Görüşme</option>
|
||||
<option value="teklif">Teklif</option>
|
||||
<option value="ziyaret">Ziyaret</option>
|
||||
<option value="arama">Arama</option>
|
||||
<option value="not">Not</option>
|
||||
</select>
|
||||
const steps = [
|
||||
{
|
||||
label: "Aktivite",
|
||||
content: (
|
||||
<>
|
||||
<div className="grid grid-cols-3 gap-3">
|
||||
<div className="grid gap-1.5">
|
||||
<Label>Tip *</Label>
|
||||
<select name="type" defaultValue={activity?.type ?? "gorusme"}
|
||||
className="border-input bg-background h-9 rounded-md border px-3 text-sm">
|
||||
<option value="gorusme">Görüşme</option>
|
||||
<option value="teklif">Teklif</option>
|
||||
<option value="ziyaret">Ziyaret</option>
|
||||
<option value="arama">Arama</option>
|
||||
<option value="not">Not</option>
|
||||
</select>
|
||||
</div>
|
||||
<div className="col-span-2 grid gap-1.5">
|
||||
<Label htmlFor="title">Başlık *</Label>
|
||||
<Input id="title" name="title" defaultValue={activity?.title} placeholder="Görüşme notu..." />
|
||||
{fe.title && <p className="text-destructive text-xs">{fe.title[0]}</p>}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-1.5">
|
||||
<Label htmlFor="title">Başlık *</Label>
|
||||
<Input id="title" name="title" defaultValue={activity?.title} placeholder="Görüşme notu..." />
|
||||
{fe.title && <p className="text-destructive text-xs">{fe.title[0]}</p>}
|
||||
<Label htmlFor="dueDate">Tarih</Label>
|
||||
<Input id="dueDate" name="dueDate" type="date"
|
||||
defaultValue={activity?.dueDate ? activity.dueDate.split("T")[0] : ""} />
|
||||
</div>
|
||||
|
||||
</>
|
||||
),
|
||||
},
|
||||
{
|
||||
label: "Bağlantı",
|
||||
content: (
|
||||
<>
|
||||
<div className="grid gap-1.5">
|
||||
<Label>Müşteri</Label>
|
||||
<select
|
||||
name="customerId"
|
||||
defaultValue={activity?.customerId ?? ""}
|
||||
className="border-input bg-background h-9 rounded-md border px-3 text-sm"
|
||||
>
|
||||
<select name="customerId" defaultValue={activity?.customerId ?? ""}
|
||||
className="border-input bg-background h-9 rounded-md border px-3 text-sm">
|
||||
<option value="">Seçiniz</option>
|
||||
{customers.map((c) => (
|
||||
<option key={c.$id} value={c.$id}>{c.name}</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-1.5">
|
||||
<Label>İlan</Label>
|
||||
<select
|
||||
name="propertyId"
|
||||
defaultValue={activity?.propertyId ?? ""}
|
||||
className="border-input bg-background h-9 rounded-md border px-3 text-sm"
|
||||
>
|
||||
<select name="propertyId" defaultValue={activity?.propertyId ?? ""}
|
||||
className="border-input bg-background h-9 rounded-md border px-3 text-sm">
|
||||
<option value="">Seçiniz</option>
|
||||
{properties.map((p) => (
|
||||
<option key={p.$id} value={p.$id}>{p.title}</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
</>
|
||||
),
|
||||
},
|
||||
{
|
||||
label: "Detay",
|
||||
content: (
|
||||
<div className="grid gap-1.5">
|
||||
<Label htmlFor="description">Açıklama</Label>
|
||||
<Textarea id="description" name="description" rows={5} defaultValue={activity?.description ?? ""} />
|
||||
</div>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
<div className="grid gap-1.5">
|
||||
<Label htmlFor="dueDate">Tarih</Label>
|
||||
<Input
|
||||
id="dueDate"
|
||||
name="dueDate"
|
||||
type="date"
|
||||
defaultValue={activity?.dueDate ? activity.dueDate.split("T")[0] : ""}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-1.5">
|
||||
<Label htmlFor="description">Açıklama</Label>
|
||||
<Textarea id="description" name="description" rows={3} defaultValue={activity?.description ?? ""} />
|
||||
</div>
|
||||
|
||||
<SheetFooter>
|
||||
<Button type="submit" disabled={isPending} className="w-full">
|
||||
{isPending && <Loader2 className="mr-2 size-4 animate-spin" />}
|
||||
{activity ? "Güncelle" : "Oluştur"}
|
||||
</Button>
|
||||
</SheetFooter>
|
||||
</form>
|
||||
</SheetContent>
|
||||
</Sheet>
|
||||
return (
|
||||
<ResponsiveSheet open={open} onOpenChange={onOpenChange}
|
||||
title={activity ? "Aktiviteyi Düzenle" : "Yeni Aktivite"}
|
||||
maxWidth="sm:max-w-lg">
|
||||
<form action={formAction}>
|
||||
<FormWizard steps={steps} isPending={isPending} submitLabel={activity ? "Güncelle" : "Oluştur"} />
|
||||
</form>
|
||||
</ResponsiveSheet>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user