diff --git a/apps/webapp/src/components/configuration/components/AddLinkedAccount.tsx b/apps/webapp/src/components/configuration/components/AddLinkedAccount.tsx index 8db7fe936..1e2fb4957 100644 --- a/apps/webapp/src/components/configuration/components/AddLinkedAccount.tsx +++ b/apps/webapp/src/components/configuration/components/AddLinkedAccount.tsx @@ -52,10 +52,11 @@ const AddLinkedAccount = () => { const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); // Prevent default form submission + //console.log("submitting with project "+ selectedProject.id_project); mutate({ linked_user_origin_id: linkedUserIdentifier, - alias: selectedOrganisation.value, - id_project: selectedProject + alias: selectedOrganisation.id_organisation, + id_project: selectedProject.id_project }); setShowNewLinkedUserDialog({open: false}) }; diff --git a/apps/webapp/src/components/shared/team-switcher.tsx b/apps/webapp/src/components/shared/team-switcher.tsx index 5b4c3ec53..6d5450b59 100644 --- a/apps/webapp/src/components/shared/team-switcher.tsx +++ b/apps/webapp/src/components/shared/team-switcher.tsx @@ -43,10 +43,11 @@ import useProjectMutation from "@/hooks/mutations/useProjectMutation" import useOrganisationMutation from "@/hooks/mutations/useOrganisationMutation" import { useEffect, useState } from "react" import useProjectStore from "@/state/projectStore" -import useOrganisationStore, { organisations } from "@/state/organisationStore" +import useOrganisationStore from "@/state/organisationStore" import useProfileStore from "@/state/profileStore" import useProjects from "@/hooks/useProjects" import { Skeleton } from "../ui/skeleton" +import useOrganisations from "@/hooks/useOrganisations" type PopoverTriggerProps = React.ComponentPropsWithoutRef @@ -67,6 +68,8 @@ export default function TeamSwitcher({ className }: TeamSwitcherProps) { const [orgName, setOrgName] = useState(''); const [projectName, setProjectName] = useState(''); + //TODO: it loads endlessly + const { data : orgs, isLoading: isloadingOrganisations, error: isOrgErr } = useOrganisations(); const { data : projects, isLoading: isloadingProjects } = useProjects(); @@ -74,14 +77,23 @@ export default function TeamSwitcher({ className }: TeamSwitcherProps) { const { selectedOrganisation, setSelectedOrganisation } = useOrganisationStore(); + console.log("error is "+ isOrgErr); + console.log("loading is "+ isloadingOrganisations); + console.log("data is "+ orgs); + + const { profile } = useProfileStore(); useEffect(()=>{ if(projects){ setSelectedProject(projects[0]); } - },[projects, setSelectedProject]) - + if(orgs){ + console.log("dddd "+ orgs[0].id_organization); + setSelectedOrganisation(orgs[0]); + } + },[projects,orgs, setSelectedProject]) + const handleOpenChange = (open: boolean) => { setShowNewDialog(prevState => ({ ...prevState, open })); @@ -171,34 +183,41 @@ export default function TeamSwitcher({ className }: TeamSwitcherProps) { } - {organisations.map((organisation) => ( + {!isloadingOrganisations && orgs ? orgs.map((org) => ( { - setSelectedOrganisation(organisation) + setSelectedOrganisation(org) setOpen(false) }} className="text-sm" > SC - {organisation.label} + {org.name} + )) + : + + - ))} + } diff --git a/apps/webapp/src/hooks/useOrganisations.tsx b/apps/webapp/src/hooks/useOrganisations.tsx index 72978a91c..497755646 100644 --- a/apps/webapp/src/hooks/useOrganisations.tsx +++ b/apps/webapp/src/hooks/useOrganisations.tsx @@ -2,16 +2,21 @@ import config from '@/utils/config'; import { useQuery } from '@tanstack/react-query'; import { organizations as Organisation } from 'api'; +const fetchOrgs = async (): Promise => { + 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(); +} + const useOrganisations = () => { return useQuery({ - queryKey: ['organisations'], - queryFn: async (): Promise => { - const response = await fetch(`${config.API_URL}/organisations`); - if (!response.ok) { - throw new Error('Network response was not ok'); - } - return response.json(); - } + queryKey: ['orgs'], + queryFn: fetchOrgs }); }; export default useOrganisations; diff --git a/apps/webapp/src/state/organisationStore.ts b/apps/webapp/src/state/organisationStore.ts index 5f93fc36a..7db72a14d 100644 --- a/apps/webapp/src/state/organisationStore.ts +++ b/apps/webapp/src/state/organisationStore.ts @@ -1,25 +1,14 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ import { create } from 'zustand'; -export const organisations = [ - { - label: "Acme Inc.", - value: "acme-inc", - } -]; - -interface OrganisationT { - label: string; - value: string; -} - interface OrganisationState { - selectedOrganisation: OrganisationT; - setSelectedOrganisation: (org: OrganisationT) => void; + selectedOrganisation: any; + setSelectedOrganisation: (org: any) => void; } const useOrganisationStore = create()((set) => ({ - selectedOrganisation: organisations[0], - setSelectedOrganisation: (org: OrganisationT) => set({ selectedOrganisation: org }), + selectedOrganisation: null, + setSelectedOrganisation: (org) => set({ selectedOrganisation: org }), })); export default useOrganisationStore;