-
Notifications
You must be signed in to change notification settings - Fork 56
UserInfos
MorganeLecurieux edited this page Jan 26, 2023
·
1 revision
Some infos needs to be accessible in the whole app and we want to avoid to always define the GQL, new query etc. To do so, we gave access to a few hooks to help access those informations:
Allow to acces the main informations of the user without refetching it all the time.
import { useCurrentUser } from "~/hooks/useCurrentUser";
const INeedTheUser = () => {
const { currentUser } = useCurrentUser();
return <div>{currentUser?.email}</div>;
};
Allow to access the informations of the currently selected organization (as user can have many)
import { useOrganizationInfos } from "~/hooks/useOrganizationInfos";
const INeedTheOrga = (dateToFormat: string) => {
const { organization, timezoneConfig, formatTimeOrgaTZ } =
useOrganizationInfos();
return (
<div>
<span>{organization?.vatRate}</span>
<span>{formatTimeOrgaTZ(dateToFormat)}</span>
<span>
{translate("text_638f743fa9a2a9545ee6409a", {
zone: translate(timezoneConfig.name),
offset: timezoneConfig.offset,
})}
</span>
</div>
);
};
Note : To make sure the infos are fetched at least once, the fragment defined in the hooks are also used in the UserIdentifier (triggered after authentication)