Skip to content

Commit 4e1d451

Browse files
committed
Add logic to save account settings to the database
1 parent b9672d8 commit 4e1d451

File tree

1 file changed

+26
-25
lines changed
  • application/account-management/WebApp/routes/admin/account

1 file changed

+26
-25
lines changed

application/account-management/WebApp/routes/admin/account/index.tsx

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ import { Trash2 } from "lucide-react";
66
import { t } from "@lingui/core/macro";
77
import { Trans } from "@lingui/react/macro";
88
import { createFileRoute } from "@tanstack/react-router";
9+
import { useUserInfo } from "@repo/infrastructure/auth/hooks";
10+
import { Form } from "@repo/ui/components/Form";
11+
import { useActionState, useState } from "react";
12+
import { api } from "@/shared/lib/api/client";
13+
import DeleteAccountConfirmation from "./-components/DeleteAccountConfirmation";
914
import { SharedSideMenu } from "@/shared/components/SharedSideMenu";
1015
import { TopMenu } from "@/shared/components/topMenu";
1116
import { Breadcrumb } from "@repo/ui/components/Breadcrumbs";
12-
import { useState } from "react";
13-
import { useUserInfo } from "@repo/infrastructure/auth/hooks";
14-
import DeleteAccountConfirmation from "./-components/DeleteAccountConfirmation";
1517

1618
export const Route = createFileRoute("/admin/account/")({
1719
component: AccountSettings
@@ -22,12 +24,12 @@ function AccountSettings() {
2224
const userInfo = useUserInfo();
2325
if (userInfo === null) return null;
2426

25-
const saveChanges = () => {
26-
console.log("Saving changes");
27-
};
27+
const [{ success, errors }, action] = useActionState(api.actionPut("/api/account-management/tenants/{id}"), {
28+
success: null
29+
});
2830

29-
const handleDeleteAccount = () => {
30-
setIsDeleteModalOpen(true);
31+
const handleFormSubmit = (formData: FormData) => {
32+
action(formData);
3133
};
3234

3335
return (
@@ -54,7 +56,13 @@ function AccountSettings() {
5456
</div>
5557
</div>
5658

57-
<div className="flex flex-col gap-4">
59+
<Form
60+
action={handleFormSubmit}
61+
validationErrors={errors}
62+
validationBehavior="aria"
63+
className="flex flex-col gap-4"
64+
>
65+
<input type="hidden" name="id" value={userInfo.tenantId} />
5866
<Label>
5967
<Trans>Logo</Trans>
6068
</Label>
@@ -71,32 +79,25 @@ function AccountSettings() {
7179
isDisabled={true}
7280
/>
7381
</div>
74-
</div>
7582

76-
<div className="flex gap-4">
77-
<Button onPress={saveChanges}>
83+
<Button type="submit">
7884
<Trans>Save changes</Trans>
7985
</Button>
80-
</div>
86+
</Form>
8187

8288
<div className="flex flex-col gap-4 mt-6">
8389
<h3 className="font-semibold">
8490
<Trans>Danger zone</Trans>
8591
</h3>
8692
<Separator />
8793
<div className="flex flex-col gap-4">
88-
<div>
89-
<h4 className="text-sm font-semibold pt-2">
90-
<Trans>Delete Account</Trans>
91-
</h4>
92-
<p className="text-xs">
93-
<Trans>
94-
Deleting the account and all associated data. This action cannot be undone, so please proceed with
95-
caution.
96-
</Trans>
97-
</p>
98-
</div>
99-
<Button variant="destructive" onPress={handleDeleteAccount} className="w-fit">
94+
<p className="text-sm font-normal">
95+
<Trans>
96+
Deleting the account and all associated data. This action cannot be undone, so please proceed with
97+
caution.
98+
</Trans>
99+
</p>
100+
<Button variant="destructive" onPress={() => setIsDeleteModalOpen(true)} className="w-fit">
100101
<Trash2 />
101102
<Trans>Delete Account</Trans>
102103
</Button>

0 commit comments

Comments
 (0)