Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/hooks/useAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ export const useAuth = (contactPersonId?: Id) => {

useEffect(() => {
const userIsAuthorized = user?.role === UserRole.ADMIN || user?.role === UserRole.COORDINATOR;
const personId = user?.personId;
if (userIsAuthorized) setIsAuthorized(true);
if (contactPersonId && personId === contactPersonId) {
if (user?.role === UserRole.VOLUNTEER && user.id === contactPersonId) {
setIsOwnProfile(true);
} else if (user?.role === UserRole.AGENT && user.personId === contactPersonId) {
setIsOwnProfile(true);
} else {
setIsOwnProfile(false);
Expand Down
24 changes: 11 additions & 13 deletions src/hooks/useVolunteerProfileSections.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const useVolunteerProfileSections = (volunteer: ApiVolunteerGet | undefin
const { t, i18n } = useTranslation();
const router = useRouter();
const searchParams = useSearchParams();
const { isAuthorized, isOwnProfile } = useAuth(volunteer?.person.id);
const { isAuthorized, isOwnProfile } = useAuth(volunteer?.id);
const hasEditingRights = isAuthorized || isOwnProfile;

const contactDetailsRef = useRef<EditableSectionRef>(null);
Expand Down Expand Up @@ -142,21 +142,19 @@ export const useVolunteerProfileSections = (volunteer: ApiVolunteerGet | undefin
<ContactDetails ref={contactDetailsRef} volunteer={volunteer} onEditingChange={handleContactEditingChange} />
),
});
sections.push({
iconName: IconName.ClipboardText,
title: t("dashboard.volunteerProfile.documents"),
subComponent: <VolunteerProfileDocument volunteer={volunteer} />,
});
}

if (isAuthorized) {
sections.push(
{
iconName: IconName.ClipboardText,
title: t("dashboard.volunteerProfile.documents"),
subComponent: <VolunteerProfileDocument volunteer={volunteer} />,
},
{
iconName: IconName.ChatCircleDots,
title: `${t("dashboard.volunteerProfile.coordinatorComments")} • ${volunteer.comments?.length ?? 0}`,
subComponent: <Comments volunteer={volunteer} />,
},
);
sections.push({
iconName: IconName.ChatCircleDots,
title: `${t("dashboard.volunteerProfile.coordinatorComments")} • ${volunteer.comments?.length ?? 0}`,
subComponent: <Comments volunteer={volunteer} />,
});
}

return {
Expand Down
Loading