Skip to content

Commit a128f00

Browse files
committed
Add logic to display the tenant name on the account page
1 parent 4e1d451 commit a128f00

File tree

4 files changed

+39
-18
lines changed

4 files changed

+39
-18
lines changed

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

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { Trans } from "@lingui/react/macro";
88
import { createFileRoute } from "@tanstack/react-router";
99
import { useUserInfo } from "@repo/infrastructure/auth/hooks";
1010
import { Form } from "@repo/ui/components/Form";
11-
import { useActionState, useState } from "react";
11+
import { useActionState, useState, useEffect } from "react";
1212
import { api } from "@/shared/lib/api/client";
1313
import DeleteAccountConfirmation from "./-components/DeleteAccountConfirmation";
1414
import { SharedSideMenu } from "@/shared/components/SharedSideMenu";
@@ -19,18 +19,26 @@ export const Route = createFileRoute("/admin/account/")({
1919
component: AccountSettings
2020
});
2121

22-
function AccountSettings() {
22+
export function AccountSettings() {
2323
const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false);
2424
const userInfo = useUserInfo();
25-
if (userInfo === null) return null;
26-
27-
const [{ success, errors }, action] = useActionState(api.actionPut("/api/account-management/tenants/{id}"), {
28-
success: null
25+
const {
26+
data: tenant,
27+
loading,
28+
refresh
29+
} = api.useApi("/api/account-management/tenants/{id}", {
30+
id: userInfo?.tenantId ?? ""
2931
});
3032

31-
const handleFormSubmit = (formData: FormData) => {
32-
action(formData);
33-
};
33+
const [{ errors, success }, action] = useActionState(api.actionPut("/api/account-management/tenants/{id}"), {});
34+
35+
useEffect(() => {
36+
if (success) {
37+
refresh();
38+
}
39+
}, [success, refresh]);
40+
41+
if (loading) return null;
3442

3543
return (
3644
<>
@@ -56,26 +64,29 @@ function AccountSettings() {
5664
</div>
5765
</div>
5866

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} />
67+
<Form action={action} validationErrors={errors} validationBehavior="aria" className="flex flex-col gap-4">
68+
<input type="hidden" name="id" value={userInfo?.tenantId ?? ""} />
6669
<Label>
6770
<Trans>Logo</Trans>
6871
</Label>
6972
<img src={logoWrap} alt={t`Logo`} className="max-h-16 max-w-64" />
7073

7174
<div className="w-full md:max-w-md">
72-
<TextField autoFocus isRequired name="name" label={t`Name`} placeholder={`E.g. ${userInfo.tenantId}`} />
75+
<TextField
76+
autoFocus
77+
isRequired
78+
name="name"
79+
defaultValue={tenant?.name ?? ""}
80+
label={t`Account name`}
81+
validationBehavior="aria"
82+
/>
7383
</div>
84+
7485
<div className="w-full md:max-w-md">
7586
<TextField
7687
name="domain"
7788
label={t`Domain`}
78-
value={`${userInfo.tenantId}.platformplatform.net`}
89+
value={`${userInfo?.tenantId ?? ""}.platformplatform.net`}
7990
isDisabled={true}
8091
/>
8192
</div>
@@ -97,6 +108,7 @@ function AccountSettings() {
97108
caution.
98109
</Trans>
99110
</p>
111+
100112
<Button variant="destructive" onPress={() => setIsDeleteModalOpen(true)} className="w-fit">
101113
<Trash2 />
102114
<Trans>Delete Account</Trans>

application/account-management/WebApp/shared/translations/locale/da-DK.po

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ msgstr ""
1616
msgid "Account"
1717
msgstr "Konto"
1818

19+
msgid "Account name"
20+
msgstr "Kontonavn"
21+
1922
msgid "Account settings"
2023
msgstr "Kontoindstillinger"
2124

application/account-management/WebApp/shared/translations/locale/en-US.po

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ msgstr ""
1616
msgid "Account"
1717
msgstr "Account"
1818

19+
msgid "Account name"
20+
msgstr "Account name"
21+
1922
msgid "Account settings"
2023
msgstr "Account settings"
2124

application/account-management/WebApp/shared/translations/locale/nl-NL.po

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ msgstr ""
1616
msgid "Account"
1717
msgstr "Account"
1818

19+
msgid "Account name"
20+
msgstr "Accountnaam"
21+
1922
msgid "Account settings"
2023
msgstr "Accountinstellingen"
2124

0 commit comments

Comments
 (0)