-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
140 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,8 +13,29 @@ import { | |
DropdownMenuSeparator, | ||
DropdownMenuTrigger, | ||
} from "@/components/ui/dropdown-menu" | ||
import useProfile from "@/hooks/useProfile"; | ||
import useProfileStore from "@/state/profileStore"; | ||
import { useEffect } from "react"; | ||
|
||
export function UserNav() { | ||
const {data} = useProfile(); | ||
if(!data) { | ||
console.log("loading profiles"); | ||
} | ||
const { profile, setProfile } = useProfileStore(); | ||
|
||
useEffect(()=> { | ||
if(data){ | ||
setProfile({ | ||
id_user: data[0].id_user, | ||
email: data[0].email, | ||
first_name: data[0].first_name, | ||
last_name: data[0].last_name, | ||
id_organization: data[0].id_organization as string, | ||
}) | ||
} | ||
}, [data, setProfile]); | ||
|
||
return ( | ||
<DropdownMenu> | ||
<DropdownMenuTrigger asChild> | ||
|
@@ -28,15 +49,16 @@ import { | |
<DropdownMenuContent className="w-56 ml-10" align="end" forceMount> | ||
<DropdownMenuLabel className="font-normal"> | ||
<div className="flex flex-col space-y-1"> | ||
<p className="text-sm font-medium leading-none">shadcn</p> | ||
<p className="text-sm font-medium leading-none"> | ||
{profile && profile.first_name} | ||
</p> | ||
<p className="text-xs leading-none text-muted-foreground"> | ||
[email protected] | ||
{profile && profile.email} | ||
</p> | ||
</div> | ||
</DropdownMenuLabel> | ||
<DropdownMenuSeparator /> | ||
<DropdownMenuGroup> | ||
|
||
<DropdownMenuItem> | ||
Profile | ||
</DropdownMenuItem> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,19 @@ | ||
//import { useQuery } from '@tanstack/react-query'; | ||
import config from '@/utils/config'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
import {users as User} from "@api/exports"; | ||
|
||
const useProfile = () => { | ||
//TODO | ||
return useQuery({ | ||
queryKey: ['profile'], | ||
queryFn: async (): Promise<User[]> => { | ||
const response = await fetch(`${config.API_URL}/auth/users`); | ||
if (!response.ok) { | ||
throw new Error('Network response was not ok'); | ||
} | ||
return response.json(); | ||
} | ||
}); | ||
}; | ||
export default useProfile; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { create } from 'zustand'; | ||
|
||
interface User { | ||
id_user: string; | ||
email: string; | ||
first_name: string; | ||
last_name: string; | ||
id_organization: string; | ||
} | ||
|
||
interface ProfileState { | ||
profile: User | null; | ||
setProfile: (profile: User) => void; | ||
} | ||
|
||
|
||
const useProfileStore = create<ProfileState>()((set) => ({ | ||
profile: null, | ||
setProfile: (profile_: User) => set({ profile: profile_ }), | ||
})); | ||
|
||
export default useProfileStore; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,14 @@ | ||
import { create } from 'zustand'; | ||
|
||
export const projects = [ | ||
{ | ||
label: "Financial Project", | ||
value: "personal", | ||
}, | ||
{ | ||
label: "Data Project", | ||
value: "personal1", | ||
}, | ||
{ | ||
label: "Marketing Project", | ||
value: "personal2", | ||
}, | ||
]; | ||
|
||
interface ProjectT { | ||
label: string; | ||
value: string; | ||
} | ||
import {projects as Project} from "@api/exports"; | ||
|
||
interface ProjectState { | ||
selectedProject: ProjectT; | ||
setSelectedProject: (project: ProjectT) => void; | ||
selectedProject: Project | null; | ||
setSelectedProject: (project: Project) => void; | ||
} | ||
|
||
const useProjectStore = create<ProjectState>()((set) => ({ | ||
selectedProject: projects[0], | ||
setSelectedProject: (project: ProjectT) => set({ selectedProject: project }), | ||
selectedProject: null, | ||
setSelectedProject: (project: Project) => set({ selectedProject: project }), | ||
})); | ||
|
||
export default useProjectStore; |