Skip to content

Commit

Permalink
Bugfix/empty org list when logged in (#5123)
Browse files Browse the repository at this point in the history
* change userstate isAfilliated() to hasAffiliation()

* use hasAffiliation() for isAffiliated default state

* fix tests
  • Loading branch information
lcampbell2 committed Feb 21, 2024
1 parent fc51f1c commit c5798ee
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 15 deletions.
4 changes: 2 additions & 2 deletions frontend/src/app/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const MyTrackerPage = lazyWithRetry(() => import('../user/MyTrackerPage'))

export function App() {
// Hooks to be used with this functional component
const { currentUser, isLoggedIn, isEmailValidated, currentTFAMethod, isAffiliated } = useUserVar()
const { currentUser, isLoggedIn, isEmailValidated, currentTFAMethod, hasAffiliation } = useUserVar()
const { i18n } = useLingui()
const { data } = useQuery(IS_LOGIN_REQUIRED, {})
const location = useLocation()
Expand Down Expand Up @@ -80,7 +80,7 @@ export function App() {
</NotificationBanner>
)
}
if (!isAffiliated()) {
if (!hasAffiliation()) {
return (
<NotificationBanner bg="yellow.250">
<Text fontWeight="medium">
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/dmarc/DmarcByDomainPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,17 @@ import { toConstantCase } from '../helpers/toConstantCase'
import { RelayPaginationControls } from '../components/RelayPaginationControls'
import { MonthSelect } from '../components/MonthSelect'
import { AffiliationFilterSwitch } from '../components/AffiliationFilterSwitch'

import { useUserVar } from '../utilities/userState'
export default function DmarcByDomainPage() {
const { i18n } = useLingui()
const currentDate = new Date()
const { hasAffiliation } = useUserVar()

const [selectedTableDisplayLimit, setSelectedTableDisplayLimit] = useState(10)
const displayLimitOptions = [5, 10, 20, 50, 100]
const [searchTerm, setSearchTerm] = useState('')
const [debouncedSearchTerm, setDebouncedSearchTerm] = useState('')
const [isAffiliated, setIsAffiliated] = useState(true)
const [isAffiliated, setIsAffiliated] = useState(hasAffiliation())

const [selectedPeriod, setSelectedPeriod] = useState('LAST30DAYS')
const [selectedYear, setSelectedYear] = useState(currentDate.getFullYear().toString())
Expand Down
16 changes: 12 additions & 4 deletions frontend/src/dmarc/__tests__/DmarcByDomainPage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ describe('<DmarcByDomainPage />', () => {
it('renders page header', async () => {
const { getAllByText } = render(
<MockedProvider mocks={mocks} addTypename={false}>
<UserVarProvider userVar={makeVar({ jwt: null, tfaSendMethod: null, userName: null })}>
<UserVarProvider
userVar={makeVar({ jwt: 'somejwt', tfaSendMethod: null, userName: null, affiliations: { totalCount: 1 } })}
>
<ChakraProvider theme={theme}>
<I18nProvider i18n={i18n}>
<MemoryRouter initialEntries={['/']} initialIndex={0}>
Expand All @@ -132,7 +134,9 @@ describe('<DmarcByDomainPage />', () => {
it('renders date selector', async () => {
const { getByText } = render(
<MockedProvider mocks={mocks} addTypename={false}>
<UserVarProvider userVar={makeVar({ jwt: null, tfaSendMethod: null, userName: null })}>
<UserVarProvider
userVar={makeVar({ jwt: 'somejwt', tfaSendMethod: null, userName: null, affiliations: { totalCount: 1 } })}
>
<ChakraProvider theme={theme}>
<I18nProvider i18n={i18n}>
<MemoryRouter initialEntries={['/']} initialIndex={0}>
Expand All @@ -148,7 +152,9 @@ describe('<DmarcByDomainPage />', () => {
it('renders table with data', async () => {
const { findByRole, findByText } = render(
<MockedProvider mocks={mocks} addTypename={false}>
<UserVarProvider userVar={makeVar({ jwt: null, tfaSendMethod: null, userName: null })}>
<UserVarProvider
userVar={makeVar({ jwt: 'somejwt', tfaSendMethod: null, userName: null, affiliations: { totalCount: 1 } })}
>
<ChakraProvider theme={theme}>
<I18nProvider i18n={i18n}>
<MemoryRouter initialEntries={['/']} initialIndex={0}>
Expand All @@ -165,7 +171,9 @@ describe('<DmarcByDomainPage />', () => {
it('can change period', async () => {
const { findByRole, findByText, getByRole } = render(
<MockedProvider mocks={mocks} addTypename={false}>
<UserVarProvider userVar={makeVar({ jwt: null, tfaSendMethod: null, userName: null })}>
<UserVarProvider
userVar={makeVar({ jwt: 'somejwt', tfaSendMethod: null, userName: null, affiliations: { totalCount: 1 } })}
>
<ChakraProvider theme={theme}>
<I18nProvider i18n={i18n}>
<MemoryRouter initialEntries={['/']} initialIndex={0}>
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/domains/DomainsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ import { AffiliationFilterSwitch } from '../components/AffiliationFilterSwitch'
import { useUserVar } from '../utilities/userState'

export default function DomainsPage() {
const { isLoggedIn } = useUserVar()
const { hasAffiliation } = useUserVar()
const { data } = useQuery(IS_USER_SUPER_ADMIN)
const toast = useToast()
const [orderDirection, setOrderDirection] = useState('ASC')
const [orderField, setOrderField] = useState('DOMAIN')
const [searchTerm, setSearchTerm] = useState('')
const [debouncedSearchTerm, setDebouncedSearchTerm] = useState('')
const [domainsPerPage, setDomainsPerPage] = useState(10)
const [isAffiliated, setIsAffiliated] = useState(isLoggedIn())
const [isAffiliated, setIsAffiliated] = useState(hasAffiliation())

const [getAllOrgDomainStatuses, { loading: allOrgDomainStatusesLoading, _error, _data }] = useLazyQuery(
GET_ALL_ORGANIZATION_DOMAINS_STATUSES_CSV,
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/organizations/Organizations.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { useUserVar } from '../utilities/userState'
import { AffiliationFilterSwitch } from '../components/AffiliationFilterSwitch'

export default function Organizations() {
const { isLoggedIn } = useUserVar()
const { isLoggedIn, hasAffiliation } = useUserVar()
const [orderDirection, setOrderDirection] = useState('ASC')
const [orderField, setOrderField] = useState('NAME')
const [searchTerm, setSearchTerm] = useState('')
Expand All @@ -29,7 +29,7 @@ export default function Organizations() {
const { isOpen: inviteRequestIsOpen, onOpen, onClose } = useDisclosure()
const [orgInfo, setOrgInfo] = useState({})
const [isVerified, setIsVerified] = useState(true)
const [isAffiliated, setIsAffiliated] = useState(isLoggedIn())
const [isAffiliated, setIsAffiliated] = useState(hasAffiliation())

const memoizedSetDebouncedSearchTermCallback = useCallback(() => {
setDebouncedSearchTerm(searchTerm)
Expand Down
10 changes: 10 additions & 0 deletions frontend/src/organizations/__tests__/Organizations.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ describe('<Organisations />', () => {
domainCount: 5,
verified: true,
summaries,
userHasPermission: false,
__typename: 'Organizations',
},
__typename: 'OrganizationsEdge',
Expand All @@ -107,6 +108,7 @@ describe('<Organisations />', () => {
domainCount: 5,
verified: true,
summaries,
userHasPermission: false,
__typename: 'Organizations',
},
__typename: 'OrganizationsEdge',
Expand All @@ -133,6 +135,7 @@ describe('<Organisations />', () => {
jwt: null,
tfaSendMethod: null,
userName: null,
affiliations: null,
})}
>
<ChakraProvider theme={theme}>
Expand Down Expand Up @@ -179,6 +182,7 @@ describe('<Organisations />', () => {
domainCount: 5,
verified: true,
summaries,
userHasPermission: false,
__typename: 'Organizations',
},
__typename: 'OrganizationsEdge',
Expand Down Expand Up @@ -221,6 +225,7 @@ describe('<Organisations />', () => {
domainCount: 5,
verified: true,
summaries,
userHasPermission: false,
__typename: 'Organizations',
},
__typename: 'OrganizationsEdge',
Expand Down Expand Up @@ -263,6 +268,7 @@ describe('<Organisations />', () => {
domainCount: 5,
verified: true,
summaries,
userHasPermission: false,
__typename: 'Organizations',
},
__typename: 'OrganizationsEdge',
Expand Down Expand Up @@ -312,6 +318,7 @@ describe('<Organisations />', () => {
jwt: null,
tfaSendMethod: null,
userName: null,
affiliations: null,
})}
>
<ChakraProvider theme={theme}>
Expand Down Expand Up @@ -390,6 +397,9 @@ describe('<Organisations />', () => {
jwt: 'somejwt',
tfaSendMethod: null,
userName: null,
affiliations: {
totalCount: 1,
},
})}
>
<ChakraProvider theme={theme}>
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/utilities/userState.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ export function UserVarProvider({
return currentUser?.tfaSendMethod
}

const isAffiliated = () => {
return currentUser?.affiliations.totalCount > 0
const hasAffiliation = () => {
return currentUser?.affiliations?.totalCount > 0
}

const login = (newUserState) => {
Expand All @@ -65,7 +65,7 @@ export function UserVarProvider({
isLoggedIn,
isEmailValidated,
currentTFAMethod,
isAffiliated,
hasAffiliation,
login,
logout,
}
Expand Down

0 comments on commit c5798ee

Please sign in to comment.