|
| 1 | +import { Button } from "@/components/ui/button"; |
| 2 | +import { Textarea } from "@/components/ui/textarea"; |
| 3 | +import { useEmails } from "@/lib/hooks/use-email"; |
| 4 | +import { useState } from "react"; |
| 5 | + |
| 6 | +export function EmailThread() { |
| 7 | + const [input, setInput] = useState(""); |
| 8 | + const { emails, addEmail } = useEmails(); |
| 9 | + |
| 10 | + const handleReply = () => { |
| 11 | + console.log(input); |
| 12 | + addEmail({ |
| 13 | + from: "me", |
| 14 | + to: "John Doe <[email protected]>", |
| 15 | + body: input, |
| 16 | + timestamp: new Date().toISOString(), |
| 17 | + }); |
| 18 | + setInput(""); |
| 19 | + }; |
| 20 | + |
| 21 | + return ( |
| 22 | + <main className="flex h-full flex-col items-center justify-between"> |
| 23 | + <div className="flex h-full w-full flex-col"> |
| 24 | + <header className="border-b px-6 py-4"> |
| 25 | + <h2 className="text-2xl font-semibold"> |
| 26 | + Email Thread: Project Kickoff Meeting |
| 27 | + </h2> |
| 28 | + </header> |
| 29 | + <div className="flex flex-1"> |
| 30 | + <div className="flex w-full flex-col border-r bg-muted"> |
| 31 | + <div className="flex-1 overflow-y-auto p-4"> |
| 32 | + <div className="space-y-4"> |
| 33 | + {emails.map((email) => ( |
| 34 | + <div |
| 35 | + key={`${email.from}-${email.timestamp}`} |
| 36 | + className="rounded-md border bg-background p-4 space-y-1" |
| 37 | + > |
| 38 | + <p className="text-sm text-muted-foreground"> |
| 39 | + {new Date(email.timestamp).toLocaleDateString()}{" "} |
| 40 | + {new Date(email.timestamp).toLocaleTimeString([], { |
| 41 | + hour: "2-digit", |
| 42 | + minute: "2-digit", |
| 43 | + hour12: true, |
| 44 | + })} |
| 45 | + </p> |
| 46 | + <div className="flex items-center justify-between"> |
| 47 | + <div className="space-y-1"> |
| 48 | + <p className="text-sm font-medium"> |
| 49 | + <span className="text-muted-foreground">From:</span>{" "} |
| 50 | + {email.from} |
| 51 | + </p> |
| 52 | + <p className="text-sm font-medium"> |
| 53 | + <span className="text-muted-foreground">To:</span>{" "} |
| 54 | + {email.to} |
| 55 | + </p> |
| 56 | + <p className="text-sm text-muted-foreground"> |
| 57 | + {email.body} |
| 58 | + </p> |
| 59 | + </div> |
| 60 | + </div> |
| 61 | + </div> |
| 62 | + ))} |
| 63 | + |
| 64 | + <hr className="my-2" /> |
| 65 | + |
| 66 | + <div className="mt-4 pt-4 space-y-2 bg-background p-4 rounded-md border"> |
| 67 | + <Textarea |
| 68 | + className="min-h-40" |
| 69 | + value={input} |
| 70 | + onChange={(e) => setInput(e.target.value)} |
| 71 | + placeholder="Write your reply..." |
| 72 | + /> |
| 73 | + <Button disabled={!input} onClick={handleReply}> |
| 74 | + Reply |
| 75 | + </Button> |
| 76 | + </div> |
| 77 | + </div> |
| 78 | + </div> |
| 79 | + </div> |
| 80 | + </div> |
| 81 | + </div> |
| 82 | + </main> |
| 83 | + ); |
| 84 | +} |
0 commit comments