forked from Lumina-eX/TaskChain
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmilestone-modal.tsx
More file actions
208 lines (198 loc) · 6.73 KB
/
Copy pathmilestone-modal.tsx
File metadata and controls
208 lines (198 loc) · 6.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
"use client"
import * as React from "react"
import { zodResolver } from "@hookform/resolvers/zod"
import { useForm } from "react-hook-form"
import * as z from "zod"
import { format } from "date-fns"
import { CalendarIcon, Loader2 } from "lucide-react"
import { cn } from "@/lib/utils"
import { Button } from "@/components/ui/button"
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog"
import {
Form,
FormControl,
FormDescription,
FormField,
FormItem,
FormLabel,
FormMessage,
} from "@/components/ui/form"
import { Input } from "@/components/ui/input"
import { Textarea } from "@/components/ui/textarea"
import {
Popover,
PopoverContent,
PopoverTrigger,
} from "@/components/ui/popover"
import { Calendar } from "@/components/ui/calendar"
const milestoneSchema = z.object({
title: z.string().min(2, {
message: "Title must be at least 2 characters.",
}),
description: z.string().min(10, {
message: "Description must be at least 10 characters.",
}),
amount: z.coerce.number().positive({
message: "Amount must be a positive number.",
}),
dueDate: z.date({
required_error: "A due date is required.",
}).refine((date) => date > new Date(), {
message: "Due date must be in the future.",
}),
})
type MilestoneFormValues = z.infer<typeof milestoneSchema>
interface MilestoneModalProps {
trigger?: React.ReactNode
projectId?: string
onSuccess?: (data: MilestoneFormValues) => void
}
export function MilestoneModal({ trigger, projectId, onSuccess }: MilestoneModalProps) {
const [open, setOpen] = React.useState(false)
const [isSubmitting, setIsSubmitting] = React.useState(false)
const form = useForm<MilestoneFormValues>({
resolver: zodResolver(milestoneSchema),
defaultValues: {
title: "",
description: "",
amount: 0,
},
})
async function onSubmit(data: MilestoneFormValues) {
setIsSubmitting(true)
try {
// Simulate API call
console.log("Submitting milestone:", { ...data, projectId })
await new Promise((resolve) => setTimeout(resolve, 1000))
onSuccess?.(data)
setOpen(false)
form.reset()
} catch (error) {
console.error("Failed to create milestone:", error)
} finally {
setIsSubmitting(false)
}
}
return (
<Dialog open={open} onOpenChange={setOpen}>
<DialogTrigger asChild>
{trigger || <Button variant="outline">Create Milestone</Button>}
</DialogTrigger>
<DialogContent className="sm:max-w-[500px] border-border/40 bg-card/95 backdrop-blur-md">
<DialogHeader>
<DialogTitle className="text-xl font-semibold">Create Project Milestone</DialogTitle>
<DialogDescription>
Hold funds in escrow and release them once the work is completed.
</DialogDescription>
</DialogHeader>
<Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4 py-4">
<FormField
control={form.control}
name="title"
render={({ field }) => (
<FormItem>
<FormLabel>Milestone Title</FormLabel>
<FormControl>
<Input placeholder="e.g. Initial Design Prototype" {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="description"
render={({ field }) => (
<FormItem>
<FormLabel>Description</FormLabel>
<FormControl>
<Textarea
placeholder="Detail the deliverables for this milestone..."
className="resize-none"
{...field}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<div className="grid grid-cols-2 gap-4">
<FormField
control={form.control}
name="amount"
render={({ field }) => (
<FormItem>
<FormLabel>Amount (USD)</FormLabel>
<FormControl>
<Input type="number" step="0.01" placeholder="0.00" {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="dueDate"
render={({ field }) => (
<FormItem className="flex flex-col">
<FormLabel className="mb-1">Due Date</FormLabel>
<Popover>
<PopoverTrigger asChild>
<FormControl>
<Button
variant={"outline"}
className={cn(
"w-full pl-3 text-left font-normal",
!field.value && "text-muted-foreground"
)}
>
{field.value ? (
format(field.value, "PPP")
) : (
<span>Pick a date</span>
)}
<CalendarIcon className="ml-auto h-4 w-4 opacity-50" />
</Button>
</FormControl>
</PopoverTrigger>
<PopoverContent className="w-auto p-0" align="start">
<Calendar
mode="single"
selected={field.value}
onSelect={field.onChange}
disabled={(date) =>
date < new Date(new Date().setHours(0, 0, 0, 0))
}
initialFocus
/>
</PopoverContent>
</Popover>
<FormMessage />
</FormItem>
)}
/>
</div>
<DialogFooter className="pt-4">
<Button type="button" variant="ghost" onClick={() => setOpen(false)}>
Cancel
</Button>
<Button type="submit" disabled={isSubmitting}>
{isSubmitting && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
Create Milestone
</Button>
</DialogFooter>
</form>
</Form>
</DialogContent>
</Dialog>
)
}