Files
cunkebao_v3/Cunkebao/app/workspace/ai-strategy/components/execution-setup.tsx
2025-04-09 09:31:09 +08:00

204 lines
7.4 KiB
TypeScript

"use client"
import { useState } from "react"
import { Button } from "@/components/ui/button"
import { Label } from "@/components/ui/label"
import { Input } from "@/components/ui/input"
import { Checkbox } from "@/components/ui/checkbox"
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"
import { Calendar } from "@/components/ui/calendar"
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover"
import { format } from "date-fns"
import { CalendarIcon, Clock } from "lucide-react"
interface ExecutionSetupProps {
formData: any
updateFormData: (data: any) => void
onNext: () => void
onBack: () => void
}
export function ExecutionSetup({ formData, updateFormData, onNext, onBack }: ExecutionSetupProps) {
const [scheduleType, setScheduleType] = useState<string>(formData.executionConfig?.scheduleType || "immediate")
const [scheduledDate, setScheduledDate] = useState<Date | undefined>(
formData.executionConfig?.scheduledTime ? new Date(formData.executionConfig.scheduledTime) : undefined,
)
const [scheduledTime, setScheduledTime] = useState<string>(
formData.executionConfig?.scheduledTime
? format(new Date(formData.executionConfig.scheduledTime), "HH:mm")
: "09:00",
)
const [notifyOnComplete, setNotifyOnComplete] = useState<boolean>(
formData.executionConfig?.notifyOnComplete !== undefined ? formData.executionConfig.notifyOnComplete : true,
)
const [importTags, setImportTags] = useState<boolean>(
formData.executionConfig?.importTags !== undefined ? formData.executionConfig.importTags : true,
)
const [sendToWechat, setSendToWechat] = useState<boolean>(
formData.executionConfig?.sendToWechat !== undefined ? formData.executionConfig.sendToWechat : false,
)
const [wechatId, setWechatId] = useState<string>(formData.executionConfig?.wechatId || "")
const handleContinue = () => {
let scheduledTimeString = ""
if (scheduleType === "scheduled" && scheduledDate) {
const [hours, minutes] = scheduledTime.split(":").map(Number)
const dateObj = new Date(scheduledDate)
dateObj.setHours(hours, minutes)
scheduledTimeString = dateObj.toISOString()
}
updateFormData({
executionConfig: {
scheduleType,
scheduledTime: scheduledTimeString,
notifyOnComplete,
importTags,
sendToWechat,
wechatId: sendToWechat ? wechatId : "",
},
})
onNext()
}
return (
<div className="space-y-6">
<div>
<h2 className="text-xl font-semibold mb-1"></h2>
<p className="text-gray-500 text-sm"></p>
</div>
<div className="space-y-4">
<Label className="text-base font-medium"></Label>
<RadioGroup value={scheduleType} onValueChange={setScheduleType} className="space-y-3">
<div className="flex items-start space-x-2">
<RadioGroupItem value="immediate" id="immediate" />
<div className="grid gap-1.5">
<Label htmlFor="immediate" className="font-medium">
</Label>
<p className="text-sm text-gray-500"></p>
</div>
</div>
<div className="flex items-start space-x-2">
<RadioGroupItem value="scheduled" id="scheduled" />
<div className="grid gap-1.5">
<Label htmlFor="scheduled" className="font-medium">
</Label>
<p className="text-sm text-gray-500"></p>
{scheduleType === "scheduled" && (
<div className="flex flex-col sm:flex-row gap-3 mt-2">
<div>
<Label htmlFor="date" className="text-sm">
</Label>
<Popover>
<PopoverTrigger asChild>
<Button variant="outline" className="w-full justify-start text-left font-normal mt-1" id="date">
<CalendarIcon className="mr-2 h-4 w-4" />
{scheduledDate ? format(scheduledDate, "yyyy-MM-dd") : "选择日期"}
</Button>
</PopoverTrigger>
<PopoverContent className="w-auto p-0">
<Calendar mode="single" selected={scheduledDate} onSelect={setScheduledDate} initialFocus />
</PopoverContent>
</Popover>
</div>
<div>
<Label htmlFor="time" className="text-sm">
</Label>
<div className="flex items-center mt-1">
<Clock className="mr-2 h-4 w-4 text-gray-400" />
<Input
id="time"
type="time"
value={scheduledTime}
onChange={(e) => setScheduledTime(e.target.value)}
className="w-full"
/>
</div>
</div>
</div>
)}
</div>
</div>
</RadioGroup>
</div>
<div className="space-y-4">
<Label className="text-base font-medium"></Label>
<div className="space-y-3">
<div className="flex items-center space-x-2">
<Checkbox
id="notify"
checked={notifyOnComplete}
onCheckedChange={(checked) => setNotifyOnComplete(checked as boolean)}
/>
<Label htmlFor="notify" className="cursor-pointer">
</Label>
</div>
<div className="flex items-center space-x-2">
<Checkbox
id="import"
checked={importTags}
onCheckedChange={(checked) => setImportTags(checked as boolean)}
/>
<Label htmlFor="import" className="cursor-pointer">
</Label>
</div>
<div className="flex items-center space-x-2">
<Checkbox
id="wechat"
checked={sendToWechat}
onCheckedChange={(checked) => setSendToWechat(checked as boolean)}
/>
<Label htmlFor="wechat" className="cursor-pointer">
</Label>
</div>
{sendToWechat && (
<div className="pl-6 pt-2">
<Label htmlFor="wechatId" className="text-sm">
</Label>
<Input
id="wechatId"
value={wechatId}
onChange={(e) => setWechatId(e.target.value)}
placeholder="输入接收报告的微信号"
className="mt-1"
/>
</div>
)}
</div>
</div>
<div className="flex justify-between pt-4">
<Button variant="outline" onClick={onBack}>
</Button>
<Button
onClick={handleContinue}
disabled={(scheduleType === "scheduled" && !scheduledDate) || (sendToWechat && !wechatId)}
>
</Button>
</div>
</div>
)
}