From 498edb831778964aaa60c0746be44f1cb397cf51 Mon Sep 17 00:00:00 2001 From: nael Date: Tue, 5 Dec 2023 21:12:50 +0100 Subject: [PATCH] :bug: Fixed org bug --- .../components/AddLinkedAccount.tsx | 1 + .../src/components/shared/team-switcher.tsx | 27 +++++++------------ apps/webapp/src/hooks/useOrganisations.tsx | 13 ++++----- 3 files changed, 16 insertions(+), 25 deletions(-) diff --git a/apps/webapp/src/components/configuration/components/AddLinkedAccount.tsx b/apps/webapp/src/components/configuration/components/AddLinkedAccount.tsx index 1e2fb4957..7010abd44 100644 --- a/apps/webapp/src/components/configuration/components/AddLinkedAccount.tsx +++ b/apps/webapp/src/components/configuration/components/AddLinkedAccount.tsx @@ -49,6 +49,7 @@ const AddLinkedAccount = () => { const {selectedOrganisation} = useOrganisationStore(); const {selectedProject} = useProjectStore(); + console.log("submitting with org "+ selectedOrganisation.id_organization); const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); // Prevent default form submission diff --git a/apps/webapp/src/components/shared/team-switcher.tsx b/apps/webapp/src/components/shared/team-switcher.tsx index 6d5450b59..a3df27a5b 100644 --- a/apps/webapp/src/components/shared/team-switcher.tsx +++ b/apps/webapp/src/components/shared/team-switcher.tsx @@ -69,18 +69,11 @@ export default function TeamSwitcher({ className }: TeamSwitcherProps) { const [projectName, setProjectName] = useState(''); //TODO: it loads endlessly - const { data : orgs, isLoading: isloadingOrganisations, error: isOrgErr } = useOrganisations(); + const { data : orgs, isLoading: isloadingOrganisations } = useOrganisations(); const { data : projects, isLoading: isloadingProjects } = useProjects(); - const { selectedProject, setSelectedProject } = useProjectStore(); const { selectedOrganisation, setSelectedOrganisation } = useOrganisationStore(); - - - console.log("error is "+ isOrgErr); - console.log("loading is "+ isloadingOrganisations); - console.log("data is "+ orgs); - const { profile } = useProfileStore(); @@ -92,7 +85,7 @@ export default function TeamSwitcher({ className }: TeamSwitcherProps) { console.log("dddd "+ orgs[0].id_organization); setSelectedOrganisation(orgs[0]); } - },[projects,orgs, setSelectedProject]) + },[projects, orgs, setSelectedProject, setSelectedOrganisation]) const handleOpenChange = (open: boolean) => { @@ -183,33 +176,33 @@ export default function TeamSwitcher({ className }: TeamSwitcherProps) { } - {!isloadingOrganisations && orgs ? orgs.map((org) => ( + {!isloadingOrganisations && orgs ? { - setSelectedOrganisation(org) + setSelectedOrganisation(orgs[0]) setOpen(false) }} className="text-sm" > SC - {org.name} + {orgs[0].name} - )) + : => { const response = await fetch(`${config.API_URL}/organisations`); - const a = await response.json(); - console.log(a[0].id_organization); - - if (!response.ok) { - throw new Error('Network response was not ok'); - } - return response.json(); + if (!response.ok) { + throw new Error('Network response was not ok'); + } + return response.json(); } const useOrganisations = () => { return useQuery({ - queryKey: ['orgs'], + queryKey: ['organisations'], queryFn: fetchOrgs }); };