Skip to content

Commit 06b1d83

Browse files
committed
fix: fix new default_product_privacy property in selected org
1 parent cf756a3 commit 06b1d83

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

hooks/useSyncUnitAndOrgFromProduct.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { useEffect } from "react";
22

3+
import type { OrganisationDetail } from "@squonk/account-server-client";
4+
import { OrganisationDetailDefaultProductPrivacy } from "@squonk/account-server-client";
35
import { useGetDefaultOrganisation } from "@squonk/account-server-client/organisation";
46
import { useGetProduct } from "@squonk/account-server-client/product";
57

@@ -22,14 +24,20 @@ export const useSyncUnitAndOrgFromProduct = () => {
2224
// First set the default org as the current org on first load
2325
useEffect(() => {
2426
// ensure the partial org is all there before "asserting" that it's an OrganisationDetail type
27+
// TODO convert this check to use a zod schema
2528
if (
2629
typeof defaultOrg?.id === "string" &&
27-
typeof defaultOrg.caller_is_member === "boolean" &&
30+
defaultOrg.caller_is_member !== undefined &&
2831
typeof defaultOrg.created === "string" &&
2932
typeof defaultOrg.name === "string" &&
30-
typeof defaultOrg.private === "boolean"
33+
defaultOrg.private !== undefined
3134
) {
32-
setOrganisation(defaultOrg as Required<typeof defaultOrg>);
35+
const defaultOrgCopy = {
36+
...defaultOrg,
37+
default_product_privacy: OrganisationDetailDefaultProductPrivacy.DEFAULT_PUBLIC,
38+
} as OrganisationDetail;
39+
40+
setOrganisation(defaultOrgCopy);
3341
}
3442
}, [defaultOrg, setOrganisation]);
3543

0 commit comments

Comments
 (0)