mirror of
https://github.com/logto-io/logto.git
synced 2024-12-16 20:26:19 -05:00
chore(console): add value for tenants api swr to reduce requests
This commit is contained in:
parent
da6f9eef5c
commit
133c50a3a4
2 changed files with 14 additions and 4 deletions
|
@ -123,7 +123,7 @@ function TenantSelector() {
|
||||||
onClose={async (tenant?: TenantInfo) => {
|
onClose={async (tenant?: TenantInfo) => {
|
||||||
if (tenant) {
|
if (tenant) {
|
||||||
toast.success(t('tenants.tenant_created', { name: tenant.name }));
|
toast.success(t('tenants.tenant_created', { name: tenant.name }));
|
||||||
void mutate();
|
void mutate([tenant, ...tenants]);
|
||||||
window.location.assign(new URL(`/${tenant.id}`, window.location.origin).toString());
|
window.location.assign(new URL(`/${tenant.id}`, window.location.origin).toString());
|
||||||
}
|
}
|
||||||
setShowCreateTenantModal(false);
|
setShowCreateTenantModal(false);
|
||||||
|
|
|
@ -69,13 +69,23 @@ function TenantBasicSettings() {
|
||||||
|
|
||||||
const saveData = async (data: { name?: string; tag?: TenantTag }) => {
|
const saveData = async (data: { name?: string; tag?: TenantTag }) => {
|
||||||
try {
|
try {
|
||||||
const { name, tag } = await api.patch(`/api/tenants/:tenantId`, {
|
const updatedTenant = await api.patch(`/api/tenants/:tenantId`, {
|
||||||
params: { tenantId: currentTenantId },
|
params: { tenantId: currentTenantId },
|
||||||
body: data,
|
body: data,
|
||||||
});
|
});
|
||||||
|
const { name, tag } = updatedTenant;
|
||||||
reset({ profile: { name, tag } });
|
reset({ profile: { name, tag } });
|
||||||
void mutate();
|
|
||||||
toast.success(t('tenant_settings.profile.tenant_info_saved'));
|
toast.success(t('tenant_settings.profile.tenant_info_saved'));
|
||||||
|
const currentTenantIndex = tenants?.findIndex(({ id }) => id === currentTenantId);
|
||||||
|
if (currentTenantIndex !== undefined && currentTenantIndex !== -1) {
|
||||||
|
void mutate([
|
||||||
|
...(tenants?.slice(0, currentTenantIndex) ?? []),
|
||||||
|
updatedTenant,
|
||||||
|
...(tenants?.slice(currentTenantIndex + 1) ?? []),
|
||||||
|
]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
void mutate([updatedTenant]);
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
setError(
|
setError(
|
||||||
error instanceof Error
|
error instanceof Error
|
||||||
|
@ -109,7 +119,7 @@ function TenantBasicSettings() {
|
||||||
try {
|
try {
|
||||||
await api.delete(`/api/tenants/:tenantId`, { params: { tenantId: currentTenantId } });
|
await api.delete(`/api/tenants/:tenantId`, { params: { tenantId: currentTenantId } });
|
||||||
setIsDeletionModalOpen(false);
|
setIsDeletionModalOpen(false);
|
||||||
void mutate();
|
void mutate((tenants ?? []).filter(({ id }) => id !== currentTenantId));
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
setError(
|
setError(
|
||||||
error instanceof Error
|
error instanceof Error
|
||||||
|
|
Loading…
Reference in a new issue