Skip to content

Commit

Permalink
Merge branch 'cisagov:master' into DarkMode
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkishpolicy authored Mar 7, 2024
2 parents f28d8b0 + 7da8691 commit e2bfde2
Show file tree
Hide file tree
Showing 4 changed files with 210 additions and 22 deletions.
7 changes: 4 additions & 3 deletions backend/src/api/organizations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,16 +339,17 @@ export const update = wrapHandler(async (event) => {
*/
export const create = wrapHandler(async (event) => {
if (!isGlobalWriteAdmin(event)) return Unauthorized;
const body = await validateBody(NewOrganization, event.body);
const body = await validateBody(NewOrUpdatedOrganization, event.body);
await connectToDatabase();

if ('tags' in body) {
body.tags = await findOrCreateTags(body.tags);
}
const organization = await Organization.create({
const organization = Organization.create({
...body,
createdBy: { id: event.requestContext.authorizer!.id },
parent: { id: body.parent }
parent: { id: body.parent },
regionId: REGION_STATE_MAP[body.stateName!] ?? null
});
const res = await organization.save();
return {
Expand Down
102 changes: 84 additions & 18 deletions frontend/src/components/OrganizationForm/OrganizationForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@ import * as orgFormStyles from './orgFormStyle';
import { Organization, OrganizationTag } from 'types';
import {
Autocomplete,
Button,
Chip,
createFilterOptions,
DialogTitle,
DialogContent,
TextField,
DialogActions,
Switch,
Button,
FormControlLabel,
Box,
Chip,
Grid,
createFilterOptions
MenuItem,
Select,
Switch,
TextField,
Typography
} from '@mui/material';

import { SelectChangeEvent } from '@mui/material/Select';
import { STATE_OPTIONS } from '../../constants/constants';
import { useAuthContext } from 'context';

const classes = orgFormStyles.classes;
Expand All @@ -31,6 +34,8 @@ export interface OrganizationFormValues {
ipBlocks: string;
isPassive: boolean;
tags: OrganizationTag[];
stateName?: string | null | undefined;
acronym?: string | null;
}

export const OrganizationForm: React.FC<{
Expand All @@ -46,7 +51,9 @@ export const OrganizationForm: React.FC<{
rootDomains: organization ? organization.rootDomains.join(', ') : '',
ipBlocks: organization ? organization.ipBlocks.join(', ') : '',
isPassive: organization ? organization.isPassive : false,
tags: []
tags: [],
stateName: organization ? organization.stateName : '',
acronym: organization ? organization.acronym : ''
});

const { apiGet } = useAuthContext();
Expand Down Expand Up @@ -79,7 +86,20 @@ export const OrganizationForm: React.FC<{
[name]: value
}));
};
const handleStateChange = (event: SelectChangeEvent<string | null>) => {
setValues((values) => ({
...values,
[event.target.name]: event.target.value
}));
};

const textFieldStyling = {
'& .MuiOutlinedInput-root': {
'&.Mui-focused fieldset': {
borderRadius: '0px'
}
}
};
return (
<StyledDialog
open={open}
Expand All @@ -89,45 +109,92 @@ export const OrganizationForm: React.FC<{
fullWidth
>
<DialogTitle id="form-dialog-title">
Create new {parent ? 'Team' : 'Organization'}
Create New {parent ? 'Team' : 'Organization'}
</DialogTitle>
<DialogContent>
Organization Name
<TextField
sx={textFieldStyling}
placeholder="Enter the Organization's Name"
size="small"
margin="dense"
id="name"
inputProps={{ maxLength: 250 }}
name="name"
label="Organization Name"
type="text"
fullWidth
value={values.name}
onChange={onTextChange}
required
helperText="Enter Organization Name"
/>
Organization Acronym
<TextField
sx={textFieldStyling}
placeholder="Enter a unique Acronym for the Organization"
size="small"
margin="dense"
id="acronym"
inputProps={{ maxLength: 250 }}
name="acronym"
type="text"
fullWidth
value={values.acronym}
onChange={onTextChange}
/>
Root Domains
<TextField
sx={textFieldStyling}
placeholder="Enter Root Domains"
size="small"
margin="dense"
id="rootDomains"
name="rootDomains"
label="Root Domains"
type="text"
fullWidth
value={values.rootDomains}
onChange={onTextChange}
/>
IP Blocks
<TextField
sx={textFieldStyling}
placeholder="Enter IP Blocks"
size="small"
margin="dense"
id="ipBlocks"
name="ipBlocks"
label="IP Blocks"
type="text"
fullWidth
value={values.ipBlocks}
onChange={onTextChange}
/>
<div className={classes.headerRow}>
<label>Tags</label>
</div>
Organization State
<Select
sx={{ mt: 1 }}
displayEmpty
size="small"
id="stateName"
value={values.stateName}
name="stateName"
onChange={handleStateChange}
fullWidth
renderValue={
values.stateName !== ''
? undefined
: () => <Typography color="#bdbdbd">Select your State</Typography>
}
>
{STATE_OPTIONS.map((stateName: string, index: number) => (
<MenuItem key={index} value={stateName}>
{stateName}
</MenuItem>
))}
</Select>
{/* TODO: Fix Tag selection issues. */}
<Typography mt={1}>Tags</Typography>
<Typography variant="caption">
Select an existing tag or add a new one.
</Typography>
<span>
{chosenTags &&
chosenTags.length > 0 &&
Expand All @@ -146,7 +213,6 @@ export const OrganizationForm: React.FC<{
></Chip>
))}
</span>
<Box>Select an existing tag or add a new one.</Box>
<Grid container>
<Grid item xs={10}>
<Autocomplete
Expand Down Expand Up @@ -222,8 +288,6 @@ export const OrganizationForm: React.FC<{
</Button>
</Grid>
</Grid>
<br></br>
<br></br>
<FormControlLabel
control={
<Switch
Expand Down Expand Up @@ -258,8 +322,10 @@ export const OrganizationForm: React.FC<{
? []
: values.ipBlocks.split(',').map((ip) => ip.trim()),
name: values.name,
stateName: values.stateName,
isPassive: values.isPassive,
tags: chosenTags,
acronym: values.acronym,
parent: parent ? parent.id : undefined
});
if (!organization) setValues(defaultValues);
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/__tests__/header.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe('Header component', () => {
});

it('shows correct links for GLOBAL_ADMIN', () => {
const { getByText, queryByText } = render(<Header />, {
const { getByText } = render(<Header />, {
authContext: {
user: { ...testUser, userType: 'globalAdmin', isRegistered: true },
currentOrganization: { ...testOrganization }
Expand Down
121 changes: 121 additions & 0 deletions frontend/src/constants/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
export const STATE_OPTIONS = [
'Alabama',
'Alaska',
'American Samoa',
'Arizona',
'Arkansas',
'California',
'Colorado',
'Commonwealth Northern Mariana Islands',
'Connecticut',
'Delaware',
'District of Columbia',
'Federal States of Micronesia',
'Florida',
'Georgia',
'Guam',
'Hawaii',
'Idaho',
'Illinois',
'Indiana',
'Iowa',
'Kansas',
'Kentucky',
'Louisiana',
'Maine',
'Maryland',
'Massachusetts',
'Michigan',
'Minnesota',
'Mississippi',
'Missouri',
'Montana',
'Nebraska',
'Nevada',
'New Hampshire',
'New Jersey',
'New Mexico',
'New York',
'North Carolina',
'North Dakota',
'Ohio',
'Oklahoma',
'Oregon',
'Pennsylvania',
'Puerto Rico',
'Republic of Marshall Islands',
'Rhode Island',
'South Carolina',
'South Dakota',
'Tennessee',
'Texas',
'Utah',
'Vermont',
'Virgin Islands',
'Virginia',
'Washington',
'West Virginia',
'Wisconsin',
'Wyoming'
];

export const STATE_ABBREVIATED_OPTIONS = [
'AL', // Alabama
'AK', // Alaska
'AS', // American Samoa
'AZ', // Arizona
'AR', // Arkansas
'CA', // California
'CO', // Colorado
'MP', // Commonwealth Northern Mariana Islands
'CT', // Connecticut
'DE', // Delaware
'DC', // District of Columbia
'FM', // Federal States of Micronesia
'FL', // Florida
'GA', // Georgia
'GU', // Guam
'HI', // Hawaii
'ID', // Idaho
'IL', // Illinois
'IN', // Indiana
'IA', // Iowa
'KS', // Kansas
'KY', // Kentucky
'LA', // Louisiana
'ME', // Maine
'MD', // Maryland
'MA', // Massachusetts
'MI', // Michigan
'MN', // Minnesota
'MS', // Mississippi
'MO', // Missouri
'MT', // Montana
'NE', // Nebraska
'NV', // Nevada
'NH', // New Hampshire
'NJ', // New Jersey
'NM', // New Mexico
'NY', // New York
'NC', // North Carolina
'ND', // North Dakota
'OH', // Ohio
'OK', // Oklahoma
'OR', // Oregon
'PA', // Pennsylvania
'PR', // Puerto Rico
'MH', // Republic of Marshall Islands
'RI', // Rhode Island
'SC', // South Carolina
'SD', // South Dakota
'TN', // Tennessee
'TX', // Texas
'UT', // Utah
'VT', // Vermont
'VI', // Virgin Islands
'VA', // Virginia
'WA', // Washington
'WV', // West Virginia
'WI', // Wisconsin
'WY' // Wyoming
];

0 comments on commit e2bfde2

Please sign in to comment.