Can update account name

This commit is contained in:
Pierre HUBERT 2025-04-09 18:47:05 +02:00
parent 8ecb5b79eb
commit 82186259d1
2 changed files with 36 additions and 3 deletions

View File

@ -49,4 +49,17 @@ export class AccountApi {
method: "PUT",
});
}
/**
* Update account
*/
static async Update(account: Account): Promise<void> {
await APIClient.exec({
uri: `/account/${account.id}`,
method: "PUT",
jsonData: {
name: account.name,
},
});
}
}

View File

@ -19,9 +19,9 @@ export function AccountsRoute(): React.ReactElement {
const setDefaultAccount = async (account: Account) => {
try {
snackbar("Default account successfully updated!");
await AccountApi.SetDefaultAccount(account);
AccountApi.SetDefaultAccount(account);
snackbar("Default account successfully updated!");
await accounts.reload();
@ -33,9 +33,25 @@ export function AccountsRoute(): React.ReactElement {
}
};
const updateAccount = async (account: Account) => {
try {
await AccountApi.Update(account);
snackbar("Account successfully updated!");
await accounts.reload();
return accounts.get(account.id);
} catch (e) {
console.error("Failed to update account!", e);
alert(`Failed to update account! ${e}`);
return account;
}
};
const columns: GridColDef<(typeof list)[number]>[] = [
{ field: "id", headerName: "ID", flex: 1 },
{ field: "name", headerName: "Name", flex: 6 },
{ field: "name", headerName: "Name", flex: 6, editable: true },
{
field: "time_create",
headerName: "Time created",
@ -88,6 +104,10 @@ export function AccountsRoute(): React.ReactElement {
return setDefaultAccount(updated);
}
if (updated.name !== original.name) {
return updateAccount(updated);
}
return original as any;
}}
/>