Skip to content

Commit ed04b6c

Browse files
authored
fix(sdk): handle project name conflict error (#831)
* chore: update apsara version in sdk demo * chore: update frontier version in sdk demo * fix: handle 409 error in project create form
1 parent 88305f5 commit ed04b6c

File tree

3 files changed

+32
-82
lines changed

3 files changed

+32
-82
lines changed

sdks/js/packages/core/react/components/organization/project/add.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const projectSchema = yup
3131
/^[a-zA-Z0-9_-]{3,50}$/,
3232
"Only numbers, letters, '-', and '_' are allowed. Spaces are not allowed."
3333
),
34-
orgId: yup.string().required()
34+
org_id: yup.string().required()
3535
})
3636
.required();
3737

@@ -42,6 +42,7 @@ export const AddProject = () => {
4242
reset,
4343
control,
4444
handleSubmit,
45+
setError,
4546
formState: { errors, isSubmitting }
4647
} = useForm({
4748
resolver: yupResolver(projectSchema)
@@ -50,7 +51,7 @@ export const AddProject = () => {
5051
const { client, activeOrganization: organization } = useFrontier();
5152

5253
useEffect(() => {
53-
reset({ orgId: organization?.id });
54+
reset({ org_id: organization?.id });
5455
}, [organization, reset]);
5556

5657
async function onSubmit(data: FormData) {
@@ -60,10 +61,16 @@ export const AddProject = () => {
6061
await client.frontierServiceCreateProject(data);
6162
toast.success('Project added');
6263
navigate({ to: '/projects' });
63-
} catch ({ error }: any) {
64-
toast.error('Something went wrong', {
65-
description: error.message
66-
});
64+
} catch (err: unknown) {
65+
if (err instanceof Response && err?.status === 409) {
66+
setError('name', {
67+
message: 'Project name already exist, please enter unique name'
68+
});
69+
} else {
70+
toast.error('Something went wrong', {
71+
description: (err as Error)?.message
72+
});
73+
}
6774
}
6875
}
6976

@@ -83,6 +90,7 @@ export const AddProject = () => {
8390
// @ts-ignore
8491
src={cross}
8592
onClick={() => navigate({ to: '/projects' })}
93+
data-test-id="frontier-sdk-new-project-close-btn"
8694
style={{ cursor: 'pointer' }}
8795
/>
8896
</Flex>

sdks/js/packages/sdk-demo/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
"lint": "next lint"
1010
},
1111
"dependencies": {
12-
"@raystack/apsara": "^0.20.4",
13-
"@raystack/frontier": "^0.32.3",
12+
"@raystack/apsara": "^0.26.2",
13+
"@raystack/frontier": "^0.40.0",
1414
"next": "14.2.5",
1515
"next-http-proxy-middleware": "^1.2.6",
1616
"react": "^18",

sdks/js/pnpm-lock.yaml

Lines changed: 16 additions & 74 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)