TypeScript
feat: make Withdrawal methods responsive
Vipul Kumard31dc6f255e5
diff --git a/src/components/pages/withdrawal-methods/add-method-dialog.tsx b/src/components/pages/withdrawal-methods/add-method-dialog.tsxindex 9181b0a..599b83d 100644--- a/src/components/pages/withdrawal-methods/add-method-dialog.tsx+++ b/src/components/pages/withdrawal-methods/add-method-dialog.tsx@@ -42,7 +42,7 @@ function cardBrand(digits: string): string {export function AddMethodDialog({ open, session, onClose }: { open: boolean; session: number; onClose: () => void }) {return (<Dialog open={open} onOpenChange={(v) => !v && onClose()}>- <DialogContent className="gap-5 p-5 sm:max-w-[520px]">+ <DialogContent className="gap-5 p-5 max-sm:pb-0 sm:max-w-[520px]"><AddMethodForm key={session} onDone={onClose} /></DialogContent></Dialog>@@ -109,7 +109,7 @@ function AddMethodForm({ onDone }: { onDone: () => void }) {setKind(v as WithdrawalKind);setNumber("");}}- className="grid grid-cols-4 gap-2"+ className="grid grid-cols-2 gap-2 sm:grid-cols-4"aria-label="Method type">{KINDS.map((k) => (@@ -148,7 +148,7 @@ function AddMethodForm({ onDone }: { onDone: () => void }) {</Field>) : (<>- <div className={cn("grid gap-3", kind === "bank" && "grid-cols-2")}>+ <div className={cn("grid gap-4 sm:gap-3", kind === "bank" && "sm:grid-cols-2")}><Field label={kind === "card" ? "Name on card" : "Account holder"} htmlFor="wm-holder"><Input id="wm-holder" required value={holder} onChange={(e) => setHolder(e.target.value)} /></Field>@@ -209,7 +209,7 @@ function AddMethodForm({ onDone }: { onDone: () => void }) {</p></div>- <DialogFooter className="-mx-5 -mb-5 bg-app px-5 py-3">+ <DialogFooter className="-mx-5 -mb-5 bg-app px-5 py-3 max-sm:mb-0 max-sm:pb-[max(12px,env(safe-area-inset-bottom))] max-sm:[&_button]:h-10"><Button type="button" onClick={onDone}>Cancel</Button>diff --git a/src/components/pages/withdrawal-methods/withdrawal-methods-page.tsx b/src/components/pages/withdrawal-methods/withdrawal-methods-page.tsxindex 1cdd299..c68ffcf 100644--- a/src/components/pages/withdrawal-methods/withdrawal-methods-page.tsx+++ b/src/components/pages/withdrawal-methods/withdrawal-methods-page.tsx@@ -1,7 +1,7 @@"use client";import { useMemo, useState } from "react";-import { ArrowDownToLineIcon, CalendarClockIcon, CheckIcon, PlusIcon, Trash2Icon, WalletCardsIcon } from "lucide-react";+import { ArrowDownToLineIcon, CalendarClockIcon, CheckIcon, PlusIcon, StarIcon, Trash2Icon, WalletCardsIcon } from "lucide-react";import { toast } from "sonner";import {AlertDialog,@@ -13,7 +13,15 @@ import {AlertDialogHeader,AlertDialogTitle,} from "@/components/ui/alert-dialog";+import { Icon } from "@/components/icon";import { Button } from "@/components/ui/button";+import {+ DropdownMenu,+ DropdownMenuContent,+ DropdownMenuItem,+ DropdownMenuSeparator,+ DropdownMenuTrigger,+} from "@/components/ui/dropdown-menu";import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";import { diffDays, formatLong, formatShort, formatWeekday } from "@/lib/dates";import type { WithdrawalMethod } from "@/lib/types";@@ -63,17 +71,23 @@ export function WithdrawalMethodsPage() {return (<div className="flex min-h-0 flex-1 flex-col overflow-y-auto scroll-thin bg-app">- <header className="sticky top-0 z-10 flex h-[68px] shrink-0 items-center gap-3 border-b border-hairline bg-surface px-4">+ <header className="sticky top-0 z-10 flex min-h-[68px] shrink-0 items-center gap-3 border-b border-hairline bg-surface px-4 py-3 md:h-[68px] md:py-0"><div className="flex min-w-0 flex-1 flex-col gap-1.5"><h2 className="t-16 text-fg">Withdrawal methods</h2>- <p className="t-14 truncate text-fg-2">Where your invoice payments are paid out</p>+ <p className="t-14 leading-[1.3] text-fg-2 md:truncate md:leading-none">Where your invoice payments are paid out</p></div>- <Button variant="brand" onClick={() => setAdding((a) => ({ open: true, session: a.session + 1 }))}>- <PlusIcon /> Add method+ {/* Phones: icon-only, so the title keeps the room */}+ <Button+ variant="brand"+ className="max-md:size-10 max-md:p-0"+ onClick={() => setAdding((a) => ({ open: true, session: a.session + 1 }))}+ >+ <PlusIcon className="max-md:size-4" /> <span className="max-md:sr-only">Add method</span></Button></header>- <div className="grid grid-cols-[minmax(0,1fr)_340px] items-start gap-4 p-4">+ {/* Below lg the side cards drop under the list (side by side on tablets) */}+ <div className="grid grid-cols-1 items-start gap-4 p-4 lg:grid-cols-[minmax(0,1fr)_340px]"><section className="overflow-hidden rounded-xl border border-hairline bg-surface"><div className="flex h-12 items-center justify-between border-b border-hairline px-4"><h3 className="t-14 text-fg">Methods</h3>@@ -95,7 +109,10 @@ export function WithdrawalMethodsPage() {) : (<ul>{methods.map((m) => (- <li key={m.id} className="flex h-[68px] items-center gap-3 border-b border-subtle px-4 last:border-b-0">+ <li+ key={m.id}+ className="flex h-[68px] items-center gap-3 border-b border-subtle px-4 last:border-b-0 max-md:pr-1.5"+ ><KindTile kind={m.kind} /><div className="flex min-w-0 flex-1 flex-col gap-1.5"><span className="flex items-center gap-2">@@ -104,17 +121,22 @@ export function WithdrawalMethodsPage() {<span className="t-12 shrink-0 rounded-md bg-brand-tint px-1.5 py-1 text-brand">Default</span>)}</span>- <span className="t-12 truncate text-fg-2">+ <span className="t-12 truncate text-fg-2 max-md:hidden">{KIND_META[m.kind].label} · {m.holder}</span>+ {/* Phones fold the number and currency columns into the second line */}+ <span className="t-12 truncate text-fg-2 tabular-nums md:hidden">+ {[masked(m.last4) || m.holder, m.currency].join(" · ")}+ </span></div>- <span className="t-14 w-24 shrink-0 text-right text-table tabular-nums">+ <span className="t-14 w-24 shrink-0 text-right text-table tabular-nums max-md:hidden">{masked(m.last4) || <span className="text-placeholder">—</span>}</span>- <span className="t-12 w-12 shrink-0 rounded-md border border-control py-1 text-center text-fg-2">+ <span className="t-12 w-12 shrink-0 rounded-md border border-control py-1 text-center text-fg-2 max-md:hidden">{m.currency}</span>- <div className="flex w-[132px] shrink-0 items-center justify-end gap-0.5">+ <MethodMenu method={m} onMakeDefault={() => makeDefault(m)} onRemove={() => setRemoveId(m.id)} />+ <div className="flex w-[132px] shrink-0 items-center justify-end gap-0.5 max-md:hidden">{!m.isDefault && (<Button size="sm" className="px-2" onClick={() => makeDefault(m)}>Set default@@ -135,7 +157,7 @@ export function WithdrawalMethodsPage() {)}</section>- <div className="flex flex-col gap-4">+ <div className="grid items-start gap-4 md:grid-cols-2 lg:grid-cols-1"><section className="overflow-hidden rounded-xl border border-hairline bg-surface"><div className="flex h-12 items-center gap-2 border-b border-hairline px-4"><CalendarClockIcon className="size-3.5 text-icon" />@@ -259,3 +281,33 @@ function Row({ label, value, muted }: { label: string; value: string; muted?: bo</div>);}++/** Phone row actions: the desktop row's "Set default" and remove buttons. */+function MethodMenu({+ method,+ onMakeDefault,+ onRemove,+}: {+ method: WithdrawalMethod;+ onMakeDefault: () => void;+ onRemove: () => void;+}) {+ return (+ <DropdownMenu>+ <DropdownMenuTrigger asChild>+ <Button variant="ghost" size="icon" className="size-10 shrink-0 md:hidden" aria-label={`Actions for ${method.label}`}>+ <Icon name="more" />+ </Button>+ </DropdownMenuTrigger>+ <DropdownMenuContent align="end" className="w-48 [&_[role^=menuitem]]:min-h-10">+ <DropdownMenuItem disabled={method.isDefault} onSelect={onMakeDefault}>+ <StarIcon /> {method.isDefault ? "Default method" : "Set as default"}+ </DropdownMenuItem>+ <DropdownMenuSeparator />+ <DropdownMenuItem variant="destructive" onSelect={onRemove}>+ <Trash2Icon /> Remove+ </DropdownMenuItem>+ </DropdownMenuContent>+ </DropdownMenu>+ );+}