Skip to content

Commit

Permalink
Update partner admin authguard to check whether partner admin is acti…
Browse files Browse the repository at this point in the history
…ve (chaynHQ#939)

* Update PartnerAdmin interface and initial store state

* Run a check against the partner admin active status in the guard

* Restore lates base changes
  • Loading branch information
haydnba authored Jun 4, 2024
1 parent 6c557c3 commit eff4b86
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 2 additions & 0 deletions app/partnerAdminSlice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import { api, GetUserResponse } from './api';

export interface PartnerAdmin {
id: string | null;
active: boolean | null;
createdAt: Date | null;
updatedAt: Date | null;
partner: PartnerContent | null;
}

const initialState: PartnerAdmin = {
id: null,
active: null,
createdAt: null,
updatedAt: null,
partner: null,
Expand Down
10 changes: 6 additions & 4 deletions guards/partnerAdminGuard.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Container, Typography } from '@mui/material';
import { Box } from '@mui/system';
import Head from 'next/head';
import Image from "next/image";
import Image from 'next/image';
import { useTranslations } from 'use-intl';
import Link from '../components/common/Link';
import { useTypedSelector } from '../hooks/store';
Expand All @@ -22,11 +22,12 @@ const imageContainerStyle = {

export function PartnerAdminGuard({ children }: { children: JSX.Element }) {
const partnerAdminId = useTypedSelector((state) => state.partnerAdmin.id);
const partnerAdminIsActive = useTypedSelector((state) => state.partnerAdmin.active);

const t = useTranslations('PartnerAdmin.accessGuard');
const tS = useTranslations('Shared');

if (!partnerAdminId) {
if (!partnerAdminId || !partnerAdminIsActive) {
return (
<Container sx={containerStyle}>
<Head>{t('title')}</Head>
Expand All @@ -37,8 +38,9 @@ export function PartnerAdminGuard({ children }: { children: JSX.Element }) {
fill
sizes="100vw"
style={{
objectFit: "contain"
}} />
objectFit: 'contain',
}}
/>
</Box>
<Typography variant="h2" component="h2" mb={2}>
{t('title')}
Expand Down

0 comments on commit eff4b86

Please sign in to comment.