Skip to content

Commit

Permalink
🐛 Fixed org bug
Browse files Browse the repository at this point in the history
  • Loading branch information
naelob committed Dec 5, 2023
1 parent 76a2dcd commit 498edb8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 10 additions & 17 deletions apps/webapp/src/components/shared/team-switcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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) => {
Expand Down Expand Up @@ -183,33 +176,33 @@ export default function TeamSwitcher({ className }: TeamSwitcherProps) {
}
</CommandGroup>
<CommandGroup key={"organisations"} heading={"Organisations"}>
{!isloadingOrganisations && orgs ? orgs.map((org) => (
{!isloadingOrganisations && orgs ?
<CommandItem
key={org.id_organization}
key={orgs[0].id_organization}
onSelect={() => {
setSelectedOrganisation(org)
setSelectedOrganisation(orgs[0])
setOpen(false)
}}
className="text-sm"
>
<Avatar className="mr-2 h-5 w-5">
<AvatarImage
src={`https://avatar.vercel.sh/${org.name}.png`}
alt={org.name}
src={`https://avatar.vercel.sh/${orgs[0].name}.png`}
alt={orgs[0].name}
className="grayscale"
/>
<AvatarFallback>SC</AvatarFallback>
</Avatar>
{org.name}
{orgs[0].name}
<CheckIcon
className={cn(
"ml-auto h-4 w-4",
selectedOrganisation?.name === org.name
selectedOrganisation?.name === orgs[0].name
? "opacity-100"
: "opacity-0"
)}
/>
</CommandItem>))
</CommandItem>
:
<CommandItem
key={"0"}
Expand Down
13 changes: 5 additions & 8 deletions apps/webapp/src/hooks/useOrganisations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@ import { organizations as Organisation } from 'api';

const fetchOrgs = async (): Promise<Organisation[]> => {
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
});
};
Expand Down

0 comments on commit 498edb8

Please sign in to comment.