Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 74 additions & 53 deletions apps/web/app/(app)/accounts/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,75 +24,96 @@ import { PageWrapper } from "@/components/PageWrapper";

export default function AccountsPage() {
const { data, isLoading, error, mutate } = useAccounts();

return (
<PageWrapper>
<PageHeader title="Accounts" description="Manage your email accounts." />

<LoadingContent loading={isLoading} error={error}>
<div className="grid grid-cols-1 gap-4 py-6 md:grid-cols-2 lg:grid-cols-3">
{data?.emailAccounts.map((emailAccount) => (
<AccountItem
key={emailAccount.id}
emailAccount={emailAccount}
onAccountDeleted={mutate}
/>
))}
<AddAccount />
</div>
</LoadingContent>
</PageWrapper>
);
}

function AccountItem({
emailAccount,
onAccountDeleted,
}: {
emailAccount: {
id: string;
name: string | null;
email: string;
image: string | null;
isPrimary: boolean;
};
onAccountDeleted: () => void;
}) {
const { execute, isExecuting } = useAction(deleteEmailAccountAction, {
onSuccess: () => {
toastSuccess({
title: "Email account deleted",
description: "The email account has been deleted successfully.",
});
mutate();
onAccountDeleted();
},
onError: (error) => {
toastError({
title: "Error deleting email account",
description: error.error.serverError || "An unknown error occurred",
});
mutate();
onAccountDeleted();
},
});

return (
<PageWrapper>
<PageHeader title="Accounts" description="Manage your email accounts." />

<LoadingContent loading={isLoading} error={error}>
<div className="grid grid-cols-1 gap-4 py-6 md:grid-cols-2 lg:grid-cols-3">
{data?.emailAccounts.map((emailAccount) => (
<Card key={emailAccount.id}>
<CardHeader className="flex flex-row items-center gap-3 space-y-0">
<Avatar>
<AvatarImage src={emailAccount.image || undefined} />
<AvatarFallback>
{emailAccount.name?.[0] || emailAccount.email?.[0]}
</AvatarFallback>
</Avatar>
<div className="flex flex-col space-y-1.5">
<CardTitle>{emailAccount.name}</CardTitle>
<CardDescription>{emailAccount.email}</CardDescription>
</div>
</CardHeader>
<CardContent className="flex justify-end gap-2">
<Link href={prefixPath(emailAccount.id, "/setup")}>
<Button variant="outline" size="sm" Icon={ArrowRight}>
View
</Button>
</Link>
{!emailAccount.isPrimary && (
<ConfirmDialog
trigger={
<Button
variant="destructiveSoft"
size="sm"
loading={isExecuting}
Icon={Trash2}
>
Delete
</Button>
}
title="Delete Account"
description={`Are you sure you want to delete "${emailAccount.email}"? This will delete all data for it on Inbox Zero.`}
confirmText="Delete"
onConfirm={() => {
execute({ emailAccountId: emailAccount.id });
}}
/>
)}
</CardContent>
</Card>
))}
<AddAccount />
<Card>
<CardHeader className="flex flex-row items-center gap-3 space-y-0">
<Avatar>
<AvatarImage src={emailAccount.image || undefined} />
<AvatarFallback>
{emailAccount.name?.[0] || emailAccount.email?.[0]}
</AvatarFallback>
</Avatar>
<div className="flex flex-col space-y-1.5">
<CardTitle>{emailAccount.name}</CardTitle>
<CardDescription>{emailAccount.email}</CardDescription>
</div>
</LoadingContent>
</PageWrapper>
</CardHeader>
<CardContent className="flex justify-end gap-2">
<Button variant="outline" size="sm" Icon={ArrowRight} asChild>
<Link href={prefixPath(emailAccount.id, "/setup")}>View</Link>
</Button>
{!emailAccount.isPrimary && (
<ConfirmDialog
trigger={
<Button
variant="destructiveSoft"
size="sm"
loading={isExecuting}
Icon={Trash2}
>
Delete
</Button>
}
title="Delete Account"
description={`Are you sure you want to delete "${emailAccount.email}"? This will delete all data for it on Inbox Zero.`}
confirmText="Delete"
onConfirm={() => {
execute({ emailAccountId: emailAccount.id });
}}
/>
)}
</CardContent>
</Card>
);
}
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v2.10.4
v2.10.5