Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix participant no access when single participant #569

Merged
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
2 changes: 1 addition & 1 deletion src/web/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function AppContent() {
return <ErrorView message='You do not have access to any participants.' />;
}
if (location.pathname !== '/account/create' && LoggedInUser && !participant) {
return <NoParticipantAccessView />;
return <NoParticipantAccessView user={LoggedInUser?.user} />;
}

const showUpdatesTour =
Expand Down
49 changes: 42 additions & 7 deletions src/web/components/Navigation/NoParticipantAccessView.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,52 @@
import { useLocation, useNavigate } from 'react-router-dom';

import { UserWithParticipantRoles } from '../../../api/services/usersService';
import { getPathWithParticipant, parseParticipantId } from '../../utils/urlHelpers';
import { ParticipantSwitcher } from './ParticipantSwitcher';

import './NoParticipantAccessView.scss';

export function NoParticipantAccessView() {
type NoParticipantAccessViewProps = Readonly<{
user: UserWithParticipantRoles | null;
}>;

export function NoParticipantAccessView({ user }: NoParticipantAccessViewProps) {
const navigate = useNavigate();
const location = useLocation();

const onBackToParticipant = () => {
let participantId = parseParticipantId(
localStorage.getItem('lastSelectedParticipantId') ?? undefined
);
if (!participantId && user?.participants && user?.participants.length > 0) {
participantId = user.participants[0].id;
}
if (participantId) {
const newPath = getPathWithParticipant(location.pathname, participantId);
navigate(newPath);
}
};

return (
<div className='no-participant-access-container'>
<p className='no-access-text instructions'>You do not have access to this participant.</p>
<p className='use-switcher-text instructions'>
Use the dropdown below to navigate to a participant you have access to.
</p>
<div className='switcher'>
<ParticipantSwitcher noInitialValue />
</div>

{(user?.participants?.length ?? 0) > 1 ? (
<>
<p className='use-switcher-text instructions'>
Use the dropdown below to navigate to a participant you have access to.
</p>
<div className='switcher'>
<ParticipantSwitcher noInitialValue />
</div>
</>
) : (
<div>
<button className='small-button' type='button' onClick={onBackToParticipant}>
Back to Your Participant
</button>
</div>
)}
</div>
);
}
Loading