|
| 1 | +import type { FormEvent, ReactNode } from "react"; |
| 2 | + |
| 3 | +import { Button } from "@/components/ui/button"; |
| 4 | +import { Input } from "@/components/ui/input"; |
| 5 | +import { Label } from "@/components/ui/label"; |
| 6 | +import { TabsContent } from "@/components/ui/tabs"; |
| 7 | + |
| 8 | +import { HandleRequestPreviewPanel } from "@/features/handle-console/components/handle-request-preview-panel"; |
| 9 | +import type { |
| 10 | + HandleSnapshot, |
| 11 | + PreviewSummaryItem, |
| 12 | + RequestPreviewState, |
| 13 | +} from "@/features/handle-console/types/handle-console.types"; |
| 14 | + |
| 15 | +type ClaimTabPanelProps = { |
| 16 | + handle: string; |
| 17 | + to: string; |
| 18 | + requestBusy: boolean; |
| 19 | + claimButtonContent: ReactNode; |
| 20 | + showConfirmedPanel: boolean; |
| 21 | + confirmedSnapshot: HandleSnapshot | null; |
| 22 | + claimAwaiting: boolean; |
| 23 | + claimHasInput: boolean; |
| 24 | + claimReady: boolean; |
| 25 | + onHandleChange: (value: string) => void; |
| 26 | + onToChange: (value: string) => void; |
| 27 | + onSubmit: (e: FormEvent) => void; |
| 28 | + onViewCurl: () => void; |
| 29 | +}; |
| 30 | + |
| 31 | +export function ClaimTabPanel({ |
| 32 | + handle, |
| 33 | + to, |
| 34 | + requestBusy, |
| 35 | + claimButtonContent, |
| 36 | + showConfirmedPanel, |
| 37 | + confirmedSnapshot, |
| 38 | + claimAwaiting, |
| 39 | + claimHasInput, |
| 40 | + claimReady, |
| 41 | + onHandleChange, |
| 42 | + onToChange, |
| 43 | + onSubmit, |
| 44 | + onViewCurl, |
| 45 | +}: ClaimTabPanelProps) { |
| 46 | + const previewState: RequestPreviewState = showConfirmedPanel |
| 47 | + ? "confirmed" |
| 48 | + : claimAwaiting |
| 49 | + ? "awaiting_confirmation" |
| 50 | + : claimHasInput |
| 51 | + ? "draft" |
| 52 | + : "empty"; |
| 53 | + |
| 54 | + const previewSummaryItems: PreviewSummaryItem[] = [ |
| 55 | + { |
| 56 | + label: "Action", |
| 57 | + value: "Claim handle", |
| 58 | + tone: "accent", |
| 59 | + }, |
| 60 | + { |
| 61 | + label: "Handle", |
| 62 | + value: |
| 63 | + showConfirmedPanel && confirmedSnapshot?.handle |
| 64 | + ? confirmedSnapshot.handle |
| 65 | + : handle.trim() || "{handle}", |
| 66 | + mono: true, |
| 67 | + tone: |
| 68 | + showConfirmedPanel && confirmedSnapshot?.handle |
| 69 | + ? "accent" |
| 70 | + : handle.trim() |
| 71 | + ? "accent" |
| 72 | + : "muted", |
| 73 | + }, |
| 74 | + { |
| 75 | + label: "Destination", |
| 76 | + value: |
| 77 | + showConfirmedPanel && confirmedSnapshot?.to |
| 78 | + ? confirmedSnapshot.to |
| 79 | + : to.trim() || "[email protected]", |
| 80 | + mono: true, |
| 81 | + tone: |
| 82 | + showConfirmedPanel && confirmedSnapshot?.to |
| 83 | + ? "default" |
| 84 | + : to.trim() |
| 85 | + ? "default" |
| 86 | + : "muted", |
| 87 | + }, |
| 88 | + ]; |
| 89 | + |
| 90 | + return ( |
| 91 | + <TabsContent value="claim" className="mt-6"> |
| 92 | + <div className="grid gap-6 lg:grid-cols-5"> |
| 93 | + <form onSubmit={onSubmit} className="space-y-5 lg:col-span-3 min-w-0"> |
| 94 | + <div className="space-y-2 min-w-0"> |
| 95 | + <Label htmlFor="handle-claim" className="text-[13px] font-medium text-[var(--text-secondary)]"> |
| 96 | + Handle |
| 97 | + </Label> |
| 98 | + <Input |
| 99 | + id="handle-claim" |
| 100 | + placeholder="extencil" |
| 101 | + value={handle} |
| 102 | + onChange={(e) => onHandleChange(e.target.value)} |
| 103 | + autoCapitalize="none" |
| 104 | + spellCheck={false} |
| 105 | + className="neu-inset" |
| 106 | + /> |
| 107 | + <p className="text-xs text-[var(--text-muted)]"> |
| 108 | + Your unique username across all domains. Once claimed, nobody else can use it. |
| 109 | + </p> |
| 110 | + </div> |
| 111 | + |
| 112 | + <div className="space-y-2"> |
| 113 | + <Label htmlFor="handle-to" className="text-[13px] font-medium text-[var(--text-secondary)]"> |
| 114 | + Destination email address |
| 115 | + </Label> |
| 116 | + <Input |
| 117 | + id="handle-to" |
| 118 | + type="email" |
| 119 | + |
| 120 | + value={to} |
| 121 | + onChange={(e) => onToChange(e.target.value)} |
| 122 | + autoCapitalize="none" |
| 123 | + spellCheck={false} |
| 124 | + className="neu-inset" |
| 125 | + /> |
| 126 | + <p className="text-xs text-[var(--text-muted)]">Must be a valid mailbox.</p> |
| 127 | + </div> |
| 128 | + |
| 129 | + <div className="flex flex-col gap-2 sm:flex-row"> |
| 130 | + <Button |
| 131 | + type="submit" |
| 132 | + className="alias-primary neu-btn-green group w-full sm:w-auto" |
| 133 | + disabled={requestBusy} |
| 134 | + > |
| 135 | + {claimButtonContent} |
| 136 | + </Button> |
| 137 | + </div> |
| 138 | + </form> |
| 139 | + |
| 140 | + <div className="hidden space-y-3 lg:col-span-2 lg:block lg:self-start"> |
| 141 | + <HandleRequestPreviewPanel |
| 142 | + intent="subscribe" |
| 143 | + state={previewState} |
| 144 | + summaryItems={previewSummaryItems} |
| 145 | + onViewCurl={onViewCurl} |
| 146 | + viewCurlLabel="View cURL command" |
| 147 | + /> |
| 148 | + </div> |
| 149 | + </div> |
| 150 | + </TabsContent> |
| 151 | + ); |
| 152 | +} |
0 commit comments