@@ -8,7 +8,7 @@ import { Trans } from "@lingui/react/macro";
88import { createFileRoute } from "@tanstack/react-router" ;
99import { useUserInfo } from "@repo/infrastructure/auth/hooks" ;
1010import { Form } from "@repo/ui/components/Form" ;
11- import { useActionState , useState } from "react" ;
11+ import { useActionState , useState , useEffect } from "react" ;
1212import { api } from "@/shared/lib/api/client" ;
1313import DeleteAccountConfirmation from "./-components/DeleteAccountConfirmation" ;
1414import { 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 >
0 commit comments