diff --git a/backend/src/api/organizations.ts b/backend/src/api/organizations.ts index cbae68f2e..371a81299 100644 --- a/backend/src/api/organizations.ts +++ b/backend/src/api/organizations.ts @@ -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 { diff --git a/frontend/src/components/OrganizationForm/OrganizationForm.tsx b/frontend/src/components/OrganizationForm/OrganizationForm.tsx index 6643a4f00..168f90dce 100644 --- a/frontend/src/components/OrganizationForm/OrganizationForm.tsx +++ b/frontend/src/components/OrganizationForm/OrganizationForm.tsx @@ -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; @@ -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<{ @@ -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(); @@ -79,7 +86,20 @@ export const OrganizationForm: React.FC<{ [name]: value })); }; + const handleStateChange = (event: SelectChangeEvent) => { + setValues((values) => ({ + ...values, + [event.target.name]: event.target.value + })); + }; + const textFieldStyling = { + '& .MuiOutlinedInput-root': { + '&.Mui-focused fieldset': { + borderRadius: '0px' + } + } + }; return ( - Create new {parent ? 'Team' : 'Organization'} + Create New {parent ? 'Team' : 'Organization'} + Organization Name + Organization Acronym + + Root Domains + IP Blocks -
- -
+ Organization State + + {/* TODO: Fix Tag selection issues. */} + Tags + + Select an existing tag or add a new one. + {chosenTags && chosenTags.length > 0 && @@ -144,7 +211,6 @@ export const OrganizationForm: React.FC<{ > ))} - Select an existing tag or add a new one. -

-

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); diff --git a/frontend/src/components/__tests__/header.spec.tsx b/frontend/src/components/__tests__/header.spec.tsx index c5c30ff4f..335595605 100644 --- a/frontend/src/components/__tests__/header.spec.tsx +++ b/frontend/src/components/__tests__/header.spec.tsx @@ -88,7 +88,7 @@ describe('Header component', () => { }); it('shows correct links for GLOBAL_ADMIN', () => { - const { getByText, queryByText } = render(
, { + const { getByText } = render(
, { authContext: { user: { ...testUser, userType: 'globalAdmin', isRegistered: true }, currentOrganization: { ...testOrganization } diff --git a/frontend/src/constants/constants.js b/frontend/src/constants/constants.js new file mode 100644 index 000000000..ec161416a --- /dev/null +++ b/frontend/src/constants/constants.js @@ -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 +];