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

Fixed Error on redirect to EventDashboard (Admin) #1972

Merged
merged 5 commits into from
May 8, 2024
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
7 changes: 5 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ function app(): JSX.Element {
<Route path="/orgpeople/:orgId" element={<OrganizationPeople />} />
<Route path="/member/:orgId" element={<MemberDetail />} />
<Route path="/orgevents/:orgId" element={<OrganizationEvents />} />

<Route
path="/event/:orgId/:eventId"
element={<EventManagement />}
/>
<Route
path="/orgactionitems/:orgId"
element={<OrganizationActionItems />}
Expand Down Expand Up @@ -164,7 +167,7 @@ function app(): JSX.Element {
<Route path="/user/events/:orgId" element={<Events />} />
<Route element={<EventDashboardScreen />}>
<Route
path="/event/:orgId/:eventId"
path="/user/event/:orgId/:eventId"
element={<EventManagement />}
/>
</Route>
Expand Down
4 changes: 2 additions & 2 deletions src/components/EventDashboardScreen/EventDashboardScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import type { TargetsType } from 'state/reducers/routesReducer';
import styles from './EventDashboardScreen.module.css';
import ProfileDropdown from 'components/ProfileDropdown/ProfileDropdown';
import useLocalStorage from 'utils/useLocalstorage';
const { getItem } = useLocalStorage();

const EventDashboardScreen = (): JSX.Element => {
const { getItem } = useLocalStorage();
const isLoggedIn = getItem('IsLoggedIn');
const adminFor = getItem('AdminFor');
const location = useLocation();
const titleKey: string | undefined = map[location.pathname.split('/')[1]];
const titleKey: string | undefined = map[location.pathname.split('/')[2]];
const { t } = useTranslation('translation', { keyPrefix: titleKey });
const [hideDrawer, setHideDrawer] = useState<boolean | null>(null);
const { orgId } = useParams();
Expand Down
30 changes: 28 additions & 2 deletions src/components/EventListCard/EventListCard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,14 @@ const renderEventListCard = (
path="/event/:orgId/"
element={<EventListCard {...props} />}
/>
<Route path="/event/:orgId/:eventId" element={<></>} />
<Route
path="/event/:orgId/:eventId"
element={<div>Event Dashboard (Admin)</div>}
/>
<Route
path="/user/event/:orgId/:eventId"
element={<div>Event Dashboard (User)</div>}
/>
</Routes>
</I18nextProvider>
</LocalizationProvider>
Expand Down Expand Up @@ -287,7 +294,7 @@ describe('Testing Event List Card', () => {
});
});

test('Should navigate to event dashboard when clicked', async () => {
test('Should navigate to event dashboard when clicked (For Admin)', async () => {
renderEventListCard(props[1]);

userEvent.click(screen.getByTestId('card'));
Expand All @@ -300,6 +307,25 @@ describe('Testing Event List Card', () => {

await waitFor(() => {
expect(screen.queryByTestId('card')).not.toBeInTheDocument();
expect(screen.queryByText('Event Dashboard (Admin)')).toBeInTheDocument();
});
});

test('Should navigate to event dashboard when clicked (For User)', async () => {
setItem('userId', '123');
renderEventListCard(props[2]);

userEvent.click(screen.getByTestId('card'));

await waitFor(() => {
expect(screen.getByTestId('showEventDashboardBtn')).toBeInTheDocument();
});

userEvent.click(screen.getByTestId('showEventDashboardBtn'));

await waitFor(() => {
expect(screen.queryByTestId('card')).not.toBeInTheDocument();
expect(screen.queryByText('Event Dashboard (User)')).toBeInTheDocument();
});
});

Expand Down
6 changes: 4 additions & 2 deletions src/components/EventListCard/EventListCardModals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ function EventListCardModals({
(registrant) => registrant._id === userId,
);
const [registerEventMutation] = useMutation(REGISTER_EVENT);
const [isRegistered, setIsRegistered] = React.useState(isInitiallyRegistered);
const [isRegistered, setIsRegistered] = useState(isInitiallyRegistered);

const registerEventHandler = async (): Promise<void> => {
if (!isRegistered) {
Expand Down Expand Up @@ -352,7 +352,9 @@ function EventListCardModals({
};

const openEventDashboard = (): void => {
navigate(`/event/${orgId}/${eventListCardProps.id}`);
const userPath = eventListCardProps.userRole === Role.USER ? 'user/' : '';
console.log(`/${userPath}event/${orgId}/${eventListCardProps.id}`);
navigate(`/${userPath}event/${orgId}/${eventListCardProps.id}`);
};

const popover = (
Expand Down
Loading