({ problem }: { problem: Prisma.ProblemCreateManyInput })
| 4 | import { Card, CardContent, CardHeader, CardTitle, Button, Input } from "@repo/ui"; |
| 5 | |
| 6 | const EditProblem = ({ problem }: { problem: Prisma.ProblemCreateManyInput }) => { |
| 7 | const [isEditing, setIsEditing] = useState(false); |
| 8 | const [id, setId] = useState<string | undefined>(problem.id); |
| 9 | const [title, setTitle] = useState(problem.title); |
| 10 | const [notionDocId, setNotionDocId] = useState(problem.notionDocId); |
| 11 | function handleEdit() { |
| 12 | if (isEditing) { |
| 13 | return setIsEditing(false); |
| 14 | } |
| 15 | setIsEditing(true); |
| 16 | } |
| 17 | function handleDiscardButton() { |
| 18 | setId(problem.id); |
| 19 | setTitle(problem.title); |
| 20 | setNotionDocId(problem.notionDocId); |
| 21 | setIsEditing(false); |
| 22 | } |
| 23 | return ( |
| 24 | <Card key={problem.id}> |
| 25 | {!isEditing && ( |
| 26 | <div> |
| 27 | <CardHeader> |
| 28 | <div className="flex justify-between"> |
| 29 | <div className="space-y-2"> |
| 30 | <CardTitle>{id}</CardTitle> |
| 31 | <CardTitle>{title}</CardTitle> |
| 32 | </div> |
| 33 | <Button variant={"outline"} className="" onClick={() => handleEdit()}> |
| 34 | Edit |
| 35 | </Button> |
| 36 | </div> |
| 37 | </CardHeader> |
| 38 | <CardContent>{notionDocId}</CardContent> |
| 39 | </div> |
| 40 | )} |
| 41 | {isEditing && ( |
| 42 | <div> |
| 43 | <CardHeader> |
| 44 | <div className="flex justify-between"> |
| 45 | <div className="w-1/2 space-y-4"> |
| 46 | <CardTitle> |
| 47 | <Input onChange={(e) => setId(e.target.value)} value={id || ""} placeholder="ID" /> |
| 48 | </CardTitle> |
| 49 | <CardTitle> |
| 50 | <Input onChange={(e) => setTitle(e.target.value)} value={title} placeholder="Title" /> |
| 51 | </CardTitle> |
| 52 | </div> |
| 53 | <div className="space-x-3"> |
| 54 | <Button variant={"outline"} className="" onClick={() => handleDiscardButton()}> |
| 55 | Discard |
| 56 | </Button> |
| 57 | <Button variant={"outline"} className="" onClick={() => handleEdit()}> |
| 58 | Save |
| 59 | </Button> |
| 60 | </div> |
| 61 | </div> |
| 62 | </CardHeader> |
| 63 | <CardContent> |
nothing calls this directly
no test coverage detected