Can update account name
This commit is contained in:
parent
8ecb5b79eb
commit
82186259d1
@ -49,4 +49,17 @@ export class AccountApi {
|
|||||||
method: "PUT",
|
method: "PUT",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update account
|
||||||
|
*/
|
||||||
|
static async Update(account: Account): Promise<void> {
|
||||||
|
await APIClient.exec({
|
||||||
|
uri: `/account/${account.id}`,
|
||||||
|
method: "PUT",
|
||||||
|
jsonData: {
|
||||||
|
name: account.name,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,9 +19,9 @@ export function AccountsRoute(): React.ReactElement {
|
|||||||
|
|
||||||
const setDefaultAccount = async (account: Account) => {
|
const setDefaultAccount = async (account: Account) => {
|
||||||
try {
|
try {
|
||||||
snackbar("Default account successfully updated!");
|
await AccountApi.SetDefaultAccount(account);
|
||||||
|
|
||||||
AccountApi.SetDefaultAccount(account);
|
snackbar("Default account successfully updated!");
|
||||||
|
|
||||||
await accounts.reload();
|
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]>[] = [
|
const columns: GridColDef<(typeof list)[number]>[] = [
|
||||||
{ field: "id", headerName: "ID", flex: 1 },
|
{ field: "id", headerName: "ID", flex: 1 },
|
||||||
{ field: "name", headerName: "Name", flex: 6 },
|
{ field: "name", headerName: "Name", flex: 6, editable: true },
|
||||||
{
|
{
|
||||||
field: "time_create",
|
field: "time_create",
|
||||||
headerName: "Time created",
|
headerName: "Time created",
|
||||||
@ -88,6 +104,10 @@ export function AccountsRoute(): React.ReactElement {
|
|||||||
return setDefaultAccount(updated);
|
return setDefaultAccount(updated);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (updated.name !== original.name) {
|
||||||
|
return updateAccount(updated);
|
||||||
|
}
|
||||||
|
|
||||||
return original as any;
|
return original as any;
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user