feat: add plan title and interval editing to settings
- Add Settings button label i18n (de: Einstellungen) - Allow editing plan title, feeding per day, feeding interval, and litter interval - Update PlanSettings component with new form fields - Add German and English translations for new settings - Update Plan type to include title property
This commit is contained in:
@@ -32,6 +32,7 @@ type Booking = {
|
|||||||
|
|
||||||
type Plan = {
|
type Plan = {
|
||||||
id: string
|
id: string
|
||||||
|
title: string
|
||||||
startDate: Date
|
startDate: Date
|
||||||
endDate: Date
|
endDate: Date
|
||||||
instructions: string | null
|
instructions: string | null
|
||||||
@@ -161,9 +162,13 @@ export function PlanDashboard({ plan, dict, settingsDict, lang }: PlanDashboardP
|
|||||||
</Button>
|
</Button>
|
||||||
<PlanSettings
|
<PlanSettings
|
||||||
planId={plan.id}
|
planId={plan.id}
|
||||||
|
initialTitle={plan.title}
|
||||||
initialWebhookUrl={plan.webhookUrl}
|
initialWebhookUrl={plan.webhookUrl}
|
||||||
initialInstructions={plan.instructions}
|
initialInstructions={plan.instructions}
|
||||||
initialNotifyAll={plan.notifyAll}
|
initialNotifyAll={plan.notifyAll}
|
||||||
|
initialFeedingPerDay={plan.feedingPerDay}
|
||||||
|
initialFeedingInterval={plan.feedingInterval}
|
||||||
|
initialLitterInterval={plan.litterInterval}
|
||||||
dict={settingsDict}
|
dict={settingsDict}
|
||||||
lang={lang}
|
lang={lang}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -8,7 +8,15 @@ import { getDictionary } from "@/get-dictionary"
|
|||||||
|
|
||||||
export async function updatePlan(
|
export async function updatePlan(
|
||||||
planId: string,
|
planId: string,
|
||||||
data: { instructions?: string; webhookUrl?: string; notifyAll?: boolean },
|
data: {
|
||||||
|
instructions?: string;
|
||||||
|
webhookUrl?: string;
|
||||||
|
notifyAll?: boolean;
|
||||||
|
title?: string;
|
||||||
|
feedingPerDay?: number;
|
||||||
|
feedingInterval?: number;
|
||||||
|
litterInterval?: number;
|
||||||
|
},
|
||||||
lang: string = "en"
|
lang: string = "en"
|
||||||
) {
|
) {
|
||||||
const dict = await getDictionary(lang as any)
|
const dict = await getDictionary(lang as any)
|
||||||
@@ -19,6 +27,10 @@ export async function updatePlan(
|
|||||||
instructions: data.instructions,
|
instructions: data.instructions,
|
||||||
webhookUrl: data.webhookUrl,
|
webhookUrl: data.webhookUrl,
|
||||||
notifyAll: data.notifyAll,
|
notifyAll: data.notifyAll,
|
||||||
|
title: data.title,
|
||||||
|
feedingPerDay: data.feedingPerDay,
|
||||||
|
feedingInterval: data.feedingInterval,
|
||||||
|
litterInterval: data.litterInterval,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -33,18 +33,26 @@ import { updatePlan } from "@/app/actions/plan"
|
|||||||
|
|
||||||
interface PlanSettingsProps {
|
interface PlanSettingsProps {
|
||||||
planId: string
|
planId: string
|
||||||
|
initialTitle: string
|
||||||
initialInstructions: string | null
|
initialInstructions: string | null
|
||||||
initialWebhookUrl: string | null
|
initialWebhookUrl: string | null
|
||||||
initialNotifyAll: boolean
|
initialNotifyAll: boolean
|
||||||
|
initialFeedingPerDay: number
|
||||||
|
initialFeedingInterval: number
|
||||||
|
initialLitterInterval: number
|
||||||
dict: any
|
dict: any
|
||||||
lang: string
|
lang: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export function PlanSettings({
|
export function PlanSettings({
|
||||||
planId,
|
planId,
|
||||||
|
initialTitle,
|
||||||
initialInstructions,
|
initialInstructions,
|
||||||
initialWebhookUrl,
|
initialWebhookUrl,
|
||||||
initialNotifyAll,
|
initialNotifyAll,
|
||||||
|
initialFeedingPerDay,
|
||||||
|
initialFeedingInterval,
|
||||||
|
initialLitterInterval,
|
||||||
dict,
|
dict,
|
||||||
lang
|
lang
|
||||||
}: PlanSettingsProps) {
|
}: PlanSettingsProps) {
|
||||||
@@ -52,9 +60,13 @@ export function PlanSettings({
|
|||||||
const [isPending, setIsPending] = useState(false)
|
const [isPending, setIsPending] = useState(false)
|
||||||
|
|
||||||
const formSchema = z.object({
|
const formSchema = z.object({
|
||||||
|
title: z.string().min(2),
|
||||||
instructions: z.string().optional(),
|
instructions: z.string().optional(),
|
||||||
webhookUrl: z.string().url().optional().or(z.literal("")),
|
webhookUrl: z.string().url().optional().or(z.literal("")),
|
||||||
notifyAll: z.boolean(),
|
notifyAll: z.boolean(),
|
||||||
|
feedingPerDay: z.number().min(1).max(10),
|
||||||
|
feedingInterval: z.number().min(1).max(30),
|
||||||
|
litterInterval: z.number().min(1).max(30),
|
||||||
})
|
})
|
||||||
|
|
||||||
type FormValues = z.infer<typeof formSchema>
|
type FormValues = z.infer<typeof formSchema>
|
||||||
@@ -62,9 +74,13 @@ export function PlanSettings({
|
|||||||
const form = useForm<FormValues>({
|
const form = useForm<FormValues>({
|
||||||
resolver: zodResolver(formSchema),
|
resolver: zodResolver(formSchema),
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
|
title: initialTitle,
|
||||||
instructions: initialInstructions || "",
|
instructions: initialInstructions || "",
|
||||||
webhookUrl: initialWebhookUrl || "",
|
webhookUrl: initialWebhookUrl || "",
|
||||||
notifyAll: initialNotifyAll,
|
notifyAll: initialNotifyAll,
|
||||||
|
feedingPerDay: initialFeedingPerDay,
|
||||||
|
feedingInterval: initialFeedingInterval,
|
||||||
|
litterInterval: initialLitterInterval,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -86,7 +102,7 @@ export function PlanSettings({
|
|||||||
<DialogTrigger asChild>
|
<DialogTrigger asChild>
|
||||||
<Button variant="outline" size="sm">
|
<Button variant="outline" size="sm">
|
||||||
<Settings className="w-4 h-4 mr-2" />
|
<Settings className="w-4 h-4 mr-2" />
|
||||||
{dict.title.split(" ")[1] || "Settings"}
|
{dict.label}
|
||||||
</Button>
|
</Button>
|
||||||
</DialogTrigger>
|
</DialogTrigger>
|
||||||
<DialogContent className="sm:max-w-[425px]">
|
<DialogContent className="sm:max-w-[425px]">
|
||||||
@@ -98,6 +114,21 @@ export function PlanSettings({
|
|||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
<Form {...form}>
|
<Form {...form}>
|
||||||
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">
|
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="title"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>{dict.titleLabel}</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input
|
||||||
|
{...field}
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="webhookUrl"
|
name="webhookUrl"
|
||||||
@@ -117,6 +148,59 @@ export function PlanSettings({
|
|||||||
</FormItem>
|
</FormItem>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
<div className="grid grid-cols-2 gap-4">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="feedingPerDay"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>{dict.feedingPerDayLabel}</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input
|
||||||
|
type="number"
|
||||||
|
{...field}
|
||||||
|
onChange={(e) => field.onChange(parseInt(e.target.value))}
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="feedingInterval"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>{dict.feedingIntervalLabel}</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input
|
||||||
|
type="number"
|
||||||
|
{...field}
|
||||||
|
onChange={(e) => field.onChange(parseInt(e.target.value))}
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="litterInterval"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>{dict.litterIntervalLabel}</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input
|
||||||
|
type="number"
|
||||||
|
{...field}
|
||||||
|
onChange={(e) => field.onChange(parseInt(e.target.value))}
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="notifyAll"
|
name="notifyAll"
|
||||||
|
|||||||
@@ -66,8 +66,10 @@
|
|||||||
"error": "Ungültiges Passwort"
|
"error": "Ungültiges Passwort"
|
||||||
},
|
},
|
||||||
"settings": {
|
"settings": {
|
||||||
|
"label": "Einstellungen",
|
||||||
"title": "Plan-Einstellungen",
|
"title": "Plan-Einstellungen",
|
||||||
"description": "Aktualisiere die Instruktionen oder den Benachrichtigungs-Webhook.",
|
"description": "Aktualisiere die Instruktionen oder den Benachrichtigungs-Webhook.",
|
||||||
|
"titleLabel": "Titel des Plans",
|
||||||
"webhookLabel": "Benachrichtigungs-Webhook (Discord/Telegram)",
|
"webhookLabel": "Benachrichtigungs-Webhook (Discord/Telegram)",
|
||||||
"webhookPlaceholder": "https://discord.com/api/webhooks/...",
|
"webhookPlaceholder": "https://discord.com/api/webhooks/...",
|
||||||
"webhookDesc": "Lass dich informieren, wenn jemand bucht oder absagt.",
|
"webhookDesc": "Lass dich informieren, wenn jemand bucht oder absagt.",
|
||||||
@@ -75,6 +77,9 @@
|
|||||||
"instructionsPlaceholder": "Futter: 2x täglich, Klo: täglich...",
|
"instructionsPlaceholder": "Futter: 2x täglich, Klo: täglich...",
|
||||||
"notifyAllLabel": "Alle Ereignisse melden",
|
"notifyAllLabel": "Alle Ereignisse melden",
|
||||||
"notifyAllDesc": "Falls deaktiviert, werden nur Absagen gemeldet.",
|
"notifyAllDesc": "Falls deaktiviert, werden nur Absagen gemeldet.",
|
||||||
|
"feedingPerDayLabel": "Wie oft am Fütterungstag füttern?",
|
||||||
|
"feedingIntervalLabel": "Alle wieviel Tage füttern?",
|
||||||
|
"litterIntervalLabel": "Alle wieviel Tage das Klo reinigen?",
|
||||||
"save": "Änderungen speichern",
|
"save": "Änderungen speichern",
|
||||||
"saving": "Speichere...",
|
"saving": "Speichere...",
|
||||||
"success": "Einstellungen aktualisiert!",
|
"success": "Einstellungen aktualisiert!",
|
||||||
|
|||||||
@@ -66,8 +66,10 @@
|
|||||||
"error": "Invalid password"
|
"error": "Invalid password"
|
||||||
},
|
},
|
||||||
"settings": {
|
"settings": {
|
||||||
|
"label": "Settings",
|
||||||
"title": "Plan Settings",
|
"title": "Plan Settings",
|
||||||
"description": "Update the cat care instructions or notification webhook.",
|
"description": "Update the cat care instructions or notification webhook.",
|
||||||
|
"titleLabel": "Plan Title",
|
||||||
"webhookLabel": "Notification Webhook (Discord/Telegram)",
|
"webhookLabel": "Notification Webhook (Discord/Telegram)",
|
||||||
"webhookPlaceholder": "https://discord.com/api/webhooks/...",
|
"webhookPlaceholder": "https://discord.com/api/webhooks/...",
|
||||||
"webhookDesc": "Get notified on Discord/Telegram when someone books or cancels.",
|
"webhookDesc": "Get notified on Discord/Telegram when someone books or cancels.",
|
||||||
@@ -75,6 +77,9 @@
|
|||||||
"instructionsPlaceholder": "Food: 2x daily, Litter: daily...",
|
"instructionsPlaceholder": "Food: 2x daily, Litter: daily...",
|
||||||
"notifyAllLabel": "Notify for all events",
|
"notifyAllLabel": "Notify for all events",
|
||||||
"notifyAllDesc": "If disabled, only cancellations will be notified.",
|
"notifyAllDesc": "If disabled, only cancellations will be notified.",
|
||||||
|
"feedingPerDayLabel": "Feeding times per feeding day",
|
||||||
|
"feedingIntervalLabel": "Feeding interval (days)",
|
||||||
|
"litterIntervalLabel": "Litter cleaning interval (days)",
|
||||||
"save": "Save changes",
|
"save": "Save changes",
|
||||||
"saving": "Saving...",
|
"saving": "Saving...",
|
||||||
"success": "Settings updated!",
|
"success": "Settings updated!",
|
||||||
|
|||||||
Reference in New Issue
Block a user