fix(workspace): ensure proper handling of updates and errors (#9752)

Added `await` to `updateWorkspaceById` in resolver for proper async
handling. Enhanced workspace settings UI with specific error handling
for subdomain conflicts and improved feedback for invalid form values.


Fix
https://github.com/twentyhq/twenty/issues/9709#issuecomment-2597919251
This commit is contained in:
Antoine Moreaux
2025-01-21 17:17:58 +01:00
committed by GitHub
parent 75ba270ba8
commit f4779a02ca
2 changed files with 35 additions and 35 deletions

View File

@ -1,3 +1,4 @@
import { ApolloError } from '@apollo/client';
import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState';
import { useRedirectToWorkspaceDomain } from '@/domain-manager/hooks/useRedirectToWorkspaceDomain';
import { domainConfigurationState } from '@/domain-manager/states/domainConfigurationState';
@ -80,44 +81,43 @@ export const SettingsDomain = () => {
const subdomainValue = watch('subdomain');
const handleSave = async () => {
try {
const values = getValues();
const values = getValues();
if (!values || !isValid || !currentWorkspace) {
throw new Error(t`Invalid form values`);
}
await updateWorkspace({
variables: {
input: {
subdomain: values.subdomain,
},
},
});
setCurrentWorkspace({
...currentWorkspace,
subdomain: values.subdomain,
});
redirectToWorkspaceDomain(values.subdomain);
} catch (error) {
if (
error instanceof Error &&
(error.message === t`Subdomain already taken` ||
error.message.endsWith(t`not allowed`))
) {
control.setError('subdomain', {
type: 'manual',
message: (error as Error).message,
});
return;
}
enqueueSnackBar((error as Error).message, {
if (!values || !isValid || !currentWorkspace) {
return enqueueSnackBar(t`Invalid form values`, {
variant: SnackBarVariant.Error,
});
}
await updateWorkspace({
variables: {
input: {
subdomain: values.subdomain,
},
},
onError: (error) => {
if (
error instanceof ApolloError &&
error.graphQLErrors[0]?.extensions?.code === 'CONFLICT'
) {
return control.setError('subdomain', {
type: 'manual',
message: t`Subdomain already taken`,
});
}
enqueueSnackBar((error as Error).message, {
variant: SnackBarVariant.Error,
});
},
onCompleted: () => {
setCurrentWorkspace({
...currentWorkspace,
subdomain: values.subdomain,
});
redirectToWorkspaceDomain(values.subdomain);
},
});
};
return (

View File

@ -103,7 +103,7 @@ export class WorkspaceResolver {
@AuthWorkspace() workspace: Workspace,
) {
try {
return this.workspaceService.updateWorkspaceById({
return await this.workspaceService.updateWorkspaceById({
...data,
id: workspace.id,
});