1+ import { v4 as uuidv4 } from 'uuid' ;
2+
13/*
24 * This file is part of NER's FinishLine and licensed under GNU AGPLv3.
35 * See the LICENSE file in the repository root folder for details.
@@ -7,13 +9,33 @@ import { createContext } from 'react';
79import { AuthenticatedUser } from 'shared' ;
810import LoadingIndicator from '../components/LoadingIndicator' ;
911import { useAuth } from '../hooks/auth.hooks' ;
12+ import { useClarity } from './ClarityProvider' ;
13+ import { fullNamePipe } from '../utils/pipes' ;
14+ import { useGetUsersTeams } from '../hooks/teams.hooks' ;
15+ import ErrorPage from '../pages/ErrorPage' ;
1016
1117export const UserContext = createContext < AuthenticatedUser | undefined > ( undefined ) ;
1218
1319const AppContextUser : React . FC = ( props ) => {
1420 const auth = useAuth ( ) ;
21+ const clarity = useClarity ( ) ;
22+ const { data : teams , isLoading : teamsIsLoading , isError : teamsIsError , error : teamsError } = useGetUsersTeams ( ) ;
23+
24+ if ( ! auth . user || teamsIsLoading || ! teams ) return < LoadingIndicator /> ;
25+
26+ if ( teamsIsError ) return < ErrorPage message = { teamsError . message } /> ;
1527
16- if ( ! auth . user ) return < LoadingIndicator /> ;
28+ if ( import . meta. env . VITE_REACT_APP_CLARITY_PROJECT_ID ) {
29+ clarity ( 'consent' ) ;
30+ clarity ( 'identify' , auth . user . email , uuidv4 ( ) , undefined , fullNamePipe ( auth . user ) ) ;
31+ clarity ( 'set' , 'role' , auth . user . role ) ;
32+ clarity ( 'set' , 'finishlineUserId' , auth . user . userId ) ;
33+ clarity (
34+ 'set' ,
35+ 'team' ,
36+ teams . map ( ( team ) => team . teamName )
37+ ) ;
38+ }
1739
1840 return < UserContext . Provider value = { auth . user } > { props . children } </ UserContext . Provider > ;
1941} ;
0 commit comments