-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add user site to new manifests (#464)
* SiteTypeSelect and SiteSelect component * serialize site details for RcraSites in a user's RcraProfile on backend * restructure RcraProfile redux Slice to hold RcraSite details * logic for using a site from the user RcraProfile slice as a site on the manifest. * selectSiteById redux selector and tests * getUserSites redux selector, test, and implementation in SiteSelect component * replace simple Manifest TS interface with zod schema type, add additionalInfoSchema to manifestSchema * Type SiteType (replaces HandlerType for clarity) and RcraSiteType which follows the RCRAInfo naming convention * add dispatch to get user RcraProfile in App.tsx so this available to all virtual DOM nodes as soon as the user logs in
- Loading branch information
1 parent
71a8331
commit 26a5217
Showing
33 changed files
with
644 additions
and
307 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
client/src/components/Manifest/QuickerSign/QuickerSignModalBtn.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
client/src/components/Manifest/SiteSelect/SiteSelect.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { screen } from '@testing-library/react'; | ||
import { SiteSelect } from 'components/Manifest/SiteSelect/SiteSelect'; | ||
import React, { useState } from 'react'; | ||
import { useForm } from 'react-hook-form'; | ||
import { renderWithProviders } from 'test-utils'; | ||
import { createMockSite } from 'test-utils/fixtures'; | ||
import { createMockPermission } from 'test-utils/fixtures/mockHandler'; | ||
|
||
function TestComponent() { | ||
const [selected, setSelected] = useState(); | ||
const { control } = useForm(); | ||
// @ts-ignore | ||
return <SiteSelect selectedSite={selected} setSelectedSite={setSelected} control={control} />; | ||
} | ||
|
||
describe('SiteSelect', () => { | ||
test('renders', () => { | ||
const mySite = createMockSite(); | ||
renderWithProviders(<TestComponent />, { | ||
preloadedState: { | ||
rcraProfile: { | ||
user: 'username', | ||
phoneNumber: '1231231234', | ||
apiUser: false, | ||
rcraSites: { | ||
VATESTGEN001: { | ||
site: mySite, | ||
permissions: createMockPermission(), | ||
}, | ||
VATEST00001: { | ||
site: mySite, | ||
permissions: createMockPermission(), | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
expect(screen.queryByTestId('siteSelect')).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { HtForm } from 'components/Ht'; | ||
import { RcraSite } from 'components/RcraSite'; | ||
import React from 'react'; | ||
import { Control, Controller } from 'react-hook-form'; | ||
import Select from 'react-select'; | ||
import { RootState, useAppSelector } from 'store'; | ||
import { getUserSites, RcraProfileState } from 'store/rcraProfileSlice/rcraProfile.slice'; | ||
|
||
interface SiteSelectProps<T> { | ||
control: Control; | ||
selectedSite: T | undefined; | ||
setSelectedSite: (option: T | undefined) => void; | ||
} | ||
|
||
export function SiteSelect({ | ||
control, | ||
selectedSite, | ||
setSelectedSite, | ||
}: SiteSelectProps<RcraSite | undefined | null>) { | ||
const rcraSite = useAppSelector(getUserSites); | ||
const siteOptions = rcraSite?.map((site) => site.site.handler); | ||
return ( | ||
<> | ||
<HtForm.Label htmlFor="site">Site</HtForm.Label> | ||
<Controller | ||
control={control} | ||
name="site" | ||
data-testid="siteSelect" | ||
render={({ field }) => ( | ||
<Select | ||
id="site" | ||
{...field} // object {name, onChange(), onBLur(), value, ref} | ||
openMenuOnFocus={false} | ||
onChange={setSelectedSite} | ||
components={{ IndicatorSeparator: () => null }} | ||
options={siteOptions} | ||
noOptionsMessage={() => 'No Sites found'} | ||
value={selectedSite} | ||
getOptionLabel={(option) => `${option.epaSiteId} -- ${option.name}`} | ||
getOptionValue={(option) => option.epaSiteId} | ||
isSearchable | ||
isClearable | ||
classNames={{ | ||
control: () => 'form-control p-0 rounded-2', | ||
}} | ||
/> | ||
)} | ||
/> | ||
</> | ||
); | ||
} |
23 changes: 23 additions & 0 deletions
23
client/src/components/Manifest/SiteSelect/SiteTypeSelect.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { screen } from '@testing-library/react'; | ||
import { SiteSelect } from 'components/Manifest/SiteSelect/SiteSelect'; | ||
import { SiteTypeSelect } from 'components/Manifest/SiteSelect/SiteTypeSelect'; | ||
import React, { useState } from 'react'; | ||
import { useForm } from 'react-hook-form'; | ||
import { renderWithProviders } from 'test-utils'; | ||
import { createMockSite } from 'test-utils/fixtures'; | ||
import { createMockPermission } from 'test-utils/fixtures/mockHandler'; | ||
|
||
function TestComponent() { | ||
const [mockSiteType, setMockSiteType] = useState(); | ||
const { control } = useForm(); | ||
// @ts-ignore | ||
return <SiteTypeSelect siteType={mockSiteType} setSiteType={setMockSiteType} control={control} />; | ||
} | ||
|
||
describe('SiteTypeSelect', () => { | ||
test('renders', () => { | ||
const mySite = createMockSite(); | ||
renderWithProviders(<TestComponent />); | ||
expect(screen.queryByTestId('siteTypeSelect')).toBeDefined(); | ||
}); | ||
}); |
Oops, something went wrong.