Skip to content

Commit

Permalink
Added date established editor
Browse files Browse the repository at this point in the history
  • Loading branch information
santi-g-s committed May 22, 2023
1 parent 25156d0 commit beccdce
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 18 deletions.
25 changes: 23 additions & 2 deletions client/src/AdminDashboard/CityDataGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
FormControlLabel,
FormGroup,
Switch,
TextField,
Toolbar,
Typography,
} from '@mui/material';
Expand All @@ -29,6 +30,9 @@ function CityDataGrid() {
const [originalIsAccredited, setOriginalIsAccredited] =
React.useState<boolean>(false);
const [originalRows, setOriginalRows] = React.useState<any[]>([]);
const [dateEstablished, setDateEstablished] = React.useState<number>(0);
const [originalDateEstablished, setOriginalDateEstablished] =
React.useState<number>(0);
const [selectedRows, setSelectedRows] = React.useState<any[]>([]);
const cityData = useData(`cities/${cityName}`);

Expand All @@ -40,9 +44,11 @@ function CityDataGrid() {
setRows(dataGridRows);
setOriginalRows(dataGridRows);

console.log(cityData.data.isAccredited);
setIsAccredited(cityData.data.isAccredited);
setOriginalIsAccredited(cityData.data.isAccredited);

setDateEstablished(cityData.data.established);
setOriginalDateEstablished(cityData.data.established);
}
}, [cityData]);

Expand All @@ -51,6 +57,7 @@ function CityDataGrid() {
const updateCityData = async (city: ICity) => {
const updatedCity = rowsToCity(city, rows) as ICity;
updatedCity.isAccredited = isAccredited;
updatedCity.established = dateEstablished;
console.log('passing data should be new: ', updatedCity);
console.log('Updating City');
await putData(`cities/${cityName}`, {
Expand All @@ -62,6 +69,7 @@ function CityDataGrid() {
setAlert(`Successfully saved changes`, AlertType.SUCCESS);
setOriginalIsAccredited(isAccredited);
setOriginalRows(rows);
setOriginalDateEstablished(dateEstablished);
}
});
};
Expand Down Expand Up @@ -100,7 +108,8 @@ function CityDataGrid() {

const isSaveDisabled =
JSON.stringify(rows) === JSON.stringify(originalRows) &&
isAccredited === originalIsAccredited;
isAccredited === originalIsAccredited &&
dateEstablished === originalDateEstablished;

return (
<Box
Expand Down Expand Up @@ -146,6 +155,18 @@ function CityDataGrid() {
below
</Typography>

<Box pt={2}>
<TextField
label="Established Date"
type="number"
value={dateEstablished}
onChange={(e: { target: { value: string } }) =>
setDateEstablished(parseInt(e.target.value, 10))
}
variant="outlined"
/>
</Box>

<Box flexDirection="row" display="flex" width="100%" py={4}>
<Button
component="button"
Expand Down
34 changes: 19 additions & 15 deletions client/src/components/cityIndicators/CityNameComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,21 +127,25 @@ function CityNameWidget({ data1 }: DefaultWidgetProps) {
}).format(population)}
</Typography>
</Box>
<Box>
<Typography variant="subtitle1">Participants</Typography>
<Typography variant="h5" sx={{ fontWeight: 700 }}>
{Intl.NumberFormat('en-US', {
notation: 'compact',
maximumFractionDigits: 1,
}).format(participants)}
</Typography>
</Box>
<Box>
<Typography variant="subtitle1">Established</Typography>
<Typography variant="h5" sx={{ fontWeight: 700 }}>
{established}
</Typography>
</Box>
{accredited && (
<>
<Box>
<Typography variant="subtitle1">Participants</Typography>
<Typography variant="h5" sx={{ fontWeight: 700 }}>
{Intl.NumberFormat('en-US', {
notation: 'compact',
maximumFractionDigits: 1,
}).format(participants)}
</Typography>
</Box>
<Box>
<Typography variant="subtitle1">Established</Typography>
<Typography variant="h5" sx={{ fontWeight: 700 }}>
{established}
</Typography>
</Box>
</>
)}
</Box>
</Paper>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ function ActiveCitiesWidget({ cities1 }: DefaultWidgetProps) {
Goal
</Typography>
<Typography variant="body2" align="right">
{totalNonAccreditedCities}
{totalCities}
</Typography>
</Box>
</Box>
Expand Down
1 change: 1 addition & 0 deletions client/src/util/types/city.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ interface ICity {
isAccredited: boolean;
countiesCovered: [string];
indicators: Map<string, Map<string, number>>;
established: number;
}

export default ICity;
4 changes: 4 additions & 0 deletions server/src/models/city.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ const CitySchema = new mongoose.Schema({
},
required: true,
},
established: {
type: Number,
required: true,
},
});

interface ICity extends mongoose.Document {
Expand Down

0 comments on commit beccdce

Please sign in to comment.