|
| 1 | +"use client"; |
| 2 | + |
| 3 | +import React from "react"; |
| 4 | +import { |
| 5 | + Select, |
| 6 | + SelectContent, |
| 7 | + SelectItem, |
| 8 | + SelectTrigger, |
| 9 | + SelectValue, |
| 10 | +} from "@/components/ui/select"; |
| 11 | +import { CarePlanListItem, CarePlanStatus, carePlanStatus } from "./models"; |
| 12 | +import { Label } from "@/components/ui/label"; |
| 13 | +import { Button } from "@/components/ui/button"; |
| 14 | + |
| 15 | +import { useRouter } from "next/navigation"; |
| 16 | + |
| 17 | +type Props = { |
| 18 | + id: string; |
| 19 | + data: CarePlanListItem | null; |
| 20 | + onCarePlanStatusChange: ( |
| 21 | + id: string, |
| 22 | + status: CarePlanStatus |
| 23 | + ) => Promise<null | undefined>; |
| 24 | +}; |
| 25 | + |
| 26 | +const Components = ({ data, id, onCarePlanStatusChange }: Props) => { |
| 27 | + const router = useRouter(); |
| 28 | + const [status, setStatus] = React.useState<CarePlanStatus | null | undefined>( |
| 29 | + data?.status |
| 30 | + ); |
| 31 | + const [loading, setLoading] = React.useState(false); |
| 32 | + return ( |
| 33 | + <div className="space-y-2"> |
| 34 | + <div className="flex flex-row gap-2 items-end"> |
| 35 | + <Label>Status</Label> |
| 36 | + <Select |
| 37 | + onValueChange={(value) => setStatus(value as CarePlanStatus)} |
| 38 | + defaultValue={data?.status} |
| 39 | + > |
| 40 | + <SelectTrigger> |
| 41 | + <SelectValue placeholder="Select a verified email to display" /> |
| 42 | + </SelectTrigger> |
| 43 | + <SelectContent> |
| 44 | + {carePlanStatus.map((status) => ( |
| 45 | + <SelectItem key={status} value={status}> |
| 46 | + {status} |
| 47 | + </SelectItem> |
| 48 | + ))} |
| 49 | + </SelectContent> |
| 50 | + </Select> |
| 51 | + {status !== data?.status && ( |
| 52 | + <Button |
| 53 | + disabled={loading} |
| 54 | + onClick={async () => { |
| 55 | + if (status) { |
| 56 | + setLoading(true); |
| 57 | + await onCarePlanStatusChange(id, status); |
| 58 | + setLoading(false); |
| 59 | + window.location.reload(); |
| 60 | + } |
| 61 | + }} |
| 62 | + > |
| 63 | + {loading ? "Saving..." : "Save"} |
| 64 | + </Button> |
| 65 | + )} |
| 66 | + </div> |
| 67 | + </div> |
| 68 | + ); |
| 69 | +}; |
| 70 | + |
| 71 | +export default Components; |
0 commit comments