the hourly rate is not being saved
This commit is contained in:
@@ -53,6 +53,12 @@ export default function AdminLayout({
|
||||
Email
|
||||
</SidebarMenuSubButton>
|
||||
</SidebarMenuSubItem>
|
||||
<SidebarMenuSubItem>
|
||||
<SidebarMenuSubButton href="/admin/settings/hourly-rate" >
|
||||
<Settings />
|
||||
Hourly Rate
|
||||
</SidebarMenuSubButton>
|
||||
</SidebarMenuSubItem>
|
||||
</SidebarMenuSub>
|
||||
</SidebarMenuItem>
|
||||
</SidebarMenu>
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState, useTransition } from 'react';
|
||||
import { Card, CardContent, CardHeader, CardTitle, CardDescription } from "@/components/ui/card";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { useToast } from "@/hooks/use-toast";
|
||||
import { getSetting, setSetting } from '@/lib/actions/settings';
|
||||
|
||||
const HourlyRateSettingsPage = () => {
|
||||
const { toast } = useToast();
|
||||
const [hourlyRate, setHourlyRate] = useState('');
|
||||
const [isPending, startTransition] = useTransition();
|
||||
|
||||
useEffect(() => {
|
||||
async function fetchHourlyRate() {
|
||||
const rate = await getSetting('hourly_rate');
|
||||
if (rate) {
|
||||
setHourlyRate(rate);
|
||||
}
|
||||
}
|
||||
fetchHourlyRate();
|
||||
}, []);
|
||||
|
||||
const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
|
||||
event.preventDefault();
|
||||
startTransition(async () => {
|
||||
try {
|
||||
await setSetting('hourly_rate', hourlyRate);
|
||||
toast({ title: "Hourly Rate Saved", description: "The hourly rate has been updated successfully." });
|
||||
} catch (error) {
|
||||
console.error("Failed to save hourly rate:", error);
|
||||
toast({ title: "Error", description: "Failed to save hourly rate.", variant: "destructive" });
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<Card className="max-w-2xl">
|
||||
<CardHeader>
|
||||
<CardTitle>Hourly Rate Settings</CardTitle>
|
||||
<CardDescription>
|
||||
Set the default hourly rate used for project estimations.
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<form onSubmit={handleSubmit} className="flex flex-col gap-4">
|
||||
<div className="flex flex-col gap-2">
|
||||
<Label htmlFor="hourlyRate">Hourly Rate ($)</Label>
|
||||
<Input
|
||||
id="hourlyRate"
|
||||
name="hourlyRate"
|
||||
type="number"
|
||||
step="0.01"
|
||||
placeholder="e.g., 100.00"
|
||||
value={hourlyRate}
|
||||
onChange={(e) => setHourlyRate(e.target.value)}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<Button type="submit" className="self-start" disabled={isPending}>
|
||||
{isPending ? 'Saving...' : 'Save Hourly Rate'}
|
||||
</Button>
|
||||
</form>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
export default HourlyRateSettingsPage;
|
||||
Reference in New Issue
Block a user