Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2104 delete manufac #2143

Merged
merged 26 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
2a09c4b
#2104-delete-manufac
will-anderson0 Feb 13, 2024
d1bd5fc
#2104-delete-manufac
will-anderson0 Feb 14, 2024
d801166
#2104-delete-manufac
will-anderson0 Feb 16, 2024
d14b2f1
frontend delete works
will-anderson0 Feb 16, 2024
124a2d7
yarn lock corrected
will-anderson0 Feb 22, 2024
07b01ba
#2104 - revert yarn.lock
RChandler234 Feb 25, 2024
d7e16e1
condensed files
will-anderson0 Feb 25, 2024
fddfc74
Sync Changes
will-anderson0 Feb 25, 2024
3efedff
Deletes out of backend
will-anderson0 Feb 28, 2024
24eadf9
Can not have 0 manufacturers
will-anderson0 Feb 28, 2024
f186a24
Changed small things
will-anderson0 Feb 29, 2024
7eb102a
Final fixes
will-anderson0 Mar 20, 2024
7758ef7
Final
will-anderson0 Mar 20, 2024
1ea99ab
Merge branch 'develop' into #2104-delete-manufac
will-anderson0 Mar 24, 2024
00a667c
Fixed Linting check
will-anderson0 Mar 24, 2024
8a37049
Merge branch '#2104-delete-manufac' of https://github.com/Northeaster…
will-anderson0 Mar 24, 2024
b102166
Removed useEffect/useState
will-anderson0 Mar 26, 2024
e8f628b
updated handleDeleteManufacturer
will-anderson0 Mar 27, 2024
d5a2711
Merge branch 'develop' into #2104-delete-manufac
ryanhowe28 Apr 4, 2024
5a758f2
Custom migration and transformer edits
will-anderson0 Apr 4, 2024
bed9eeb
Merge branch '#2104-delete-manufac' of https://github.com/Northeaster…
will-anderson0 Apr 4, 2024
c03a84f
soft delete manufacturers
will-anderson0 Apr 7, 2024
02c5b94
update tests
will-anderson0 Apr 7, 2024
7413010
2104 - fix typescript check and test
RChandler234 Apr 19, 2024
4c6e3fb
#2104 - linting
RChandler234 Apr 19, 2024
b22f0bb
#2104 - fix frontend
RChandler234 Apr 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/frontend/src/apis/bom.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ export const createManufacturer = async (name: string) => {
return data;
};

/**
* Requests to delete a manufacturer.
* @param manufacturer The manufacturer to delete
* @returns The deleted manufacturer
*/
export const deleteManufacturer = async (name: string) => {
const { data } = await axios.delete(apiUrls.bomDeleteManufacturer(name));
return data;
};

/**
* Requests to create a material type.
* @param materialType The material type to create
Expand Down
22 changes: 22 additions & 0 deletions src/frontend/src/hooks/bom.hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
assignMaterialToAssembly,
createAssembly,
createManufacturer,
deleteManufacturer,
createMaterial,
createMaterialType,
createUnit,
Expand Down Expand Up @@ -175,6 +176,27 @@ export const useCreateManufacturer = () => {
);
};

/**
* Custom React hook to delete a material.
* @param materialId The material to delete's id
* @returns mutation function to delete a material
*/
export const useDeleteManufacturer = () => {
const queryClient = useQueryClient();
return useMutation<any, Error, { manufacturerName: string }>(
['manufacturer', 'delete'],
async (payload: { manufacturerName: string }) => {
const data = await deleteManufacturer(payload.manufacturerName);
return data;
},
{
onSuccess: () => {
queryClient.invalidateQueries(['materials', 'manufacturers']);
ryanhowe28 marked this conversation as resolved.
Show resolved Hide resolved
}
}
ryanhowe28 marked this conversation as resolved.
Show resolved Hide resolved
);
};

/**
* Custom React hook to create a unit.
* @returns mutation function to create a unit
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Typography } from '@mui/material';
import NERModal from '../../../components/NERModal';

interface ManufacturerDeleteModalProps {
name: string;
onDelete: () => void;
onHide: () => void;
}

const ManufacturerDeleteModal: React.FC<ManufacturerDeleteModalProps> = ({
name,
onDelete,
onHide
}: ManufacturerDeleteModalProps) => {
return (
<NERModal open={true} onHide={onHide} title="Warning!" cancelText="Cancel" submitText="Delete" onSubmit={onDelete}>
<Typography>Are you sure you want to delete this manufacturer: {name}</Typography>
</NERModal>
);
};

export default ManufacturerDeleteModal;
Original file line number Diff line number Diff line change
@@ -1,35 +1,104 @@
import { TableRow, TableCell, Box } from '@mui/material';
import DeleteIcon from '@mui/icons-material/Delete';
import { Box, Grid, IconButton, TableCell, TableRow } from '@mui/material';
import LoadingIndicator from '../../../components/LoadingIndicator';
import { NERButton } from '../../../components/NERButton';
import { useDeleteManufacturer, useGetAllManufacturers } from '../../../hooks/bom.hooks';
import { useToast } from '../../../hooks/toasts.hooks';
import { datePipe } from '../../../utils/pipes';
import ErrorPage from '../../ErrorPage';
import { NERButton } from '../../../components/NERButton';
import { useState } from 'react';
import AdminToolTable from '../AdminToolTable';
import { useGetAllManufacturers } from '../../../hooks/bom.hooks';
import CreateManufacturerModal from './CreateManufacturerFormModal';
import ManufacturerDeleteModal from './ManufacturerDeleteModal';
import { useState } from 'react';

interface ManufacturerDeleteButtonProps {
name: string;
onDelete: (name: string) => void;
}

const ManufacturerTable: React.FC = () => {
const {
data: manufactureres,
isLoading: manufactureresIsLoading,
data: manufacturers,
isLoading: manufacturersIsLoading,
isError: manufacturersIsError,
error: manufacturersError
} = useGetAllManufacturers();
const [createModalShow, setCreateModalShow] = useState<boolean>(false);
const { mutateAsync } = useDeleteManufacturer();
const toast = useToast();

if (!manufactureres || manufactureresIsLoading) {
if (!manufacturers || manufacturersIsLoading) {
return <LoadingIndicator />;
will-anderson0 marked this conversation as resolved.
Show resolved Hide resolved
}
if (manufacturersIsError) {
return <ErrorPage message={manufacturersError?.message} />;
}

const manufacturersTableRows = manufactureres.map((manufacturer) => (
const handleDeleteManufacturer = async (manufacturerName: string) => {
try {
will-anderson0 marked this conversation as resolved.
Show resolved Hide resolved
await mutateAsync({ manufacturerName: manufacturerName });
toast.success(`Manufacturer: ${manufacturerName} Deleted Successfully!`);
} catch (error: unknown) {
if (error instanceof Error) {
toast.error(error.message);
}
}
};

will-anderson0 marked this conversation as resolved.
Show resolved Hide resolved
const ManufacturerDeleteButton: React.FC<ManufacturerDeleteButtonProps> = ({ name, onDelete }) => {
const [showDeleteModal, setShowDeleteModal] = useState(false);

const handleDeleteSubmit = () => {
onDelete(name);
setShowDeleteModal(false);
};

return (
<>
<IconButton
onClick={() => setShowDeleteModal(true)}
sx={{
color: 'Red',
width: 'auto',
height: 'auto',
padding: 0.1,
borderRadius: '5px'
}}
>
<Box
sx={{
border: '2px solid red',
borderRadius: '5px',
width: '24px',
height: '24px',
display: 'flex',
justifyContent: 'center',
alignItems: 'center'
}}
>
<DeleteIcon sx={{ fontSize: 'small' }} />
</Box>
</IconButton>
{showDeleteModal && (
<ManufacturerDeleteModal name={name} onDelete={handleDeleteSubmit} onHide={() => setShowDeleteModal(false)} />
)}
</>
);
};

const manufacturersTableRows = manufacturers.map((manufacturers) => (
<TableRow>
<TableCell align="left" sx={{ border: '2px solid black' }}>
{datePipe(manufacturer.dateCreated)}
{datePipe(manufacturers.dateCreated)}
</TableCell>
<TableCell sx={{ border: '2px solid black' }}>
<Grid container justifyContent="space-between">
<Grid sx={{ align: 'left' }}>{manufacturers.name}</Grid>
<Grid>
<ManufacturerDeleteButton name={manufacturers.name} onDelete={handleDeleteManufacturer} />
</Grid>
</Grid>
</TableCell>
<TableCell sx={{ border: '2px solid black' }}>{manufacturer.name}</TableCell>
</TableRow>
));

Expand Down
2 changes: 2 additions & 0 deletions src/frontend/src/utils/urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ const bomDeleteMaterial = (materialId: string) => `${materialEndpoints()}/${mate
const bomCreateAssembly = (wbsNum: WbsNumber) => `${assemblyEndpoints()}/${wbsPipe(wbsNum)}/create`;
const bomAssignAssembly = (materialId: string) => `${materialEndpoints()}/${materialId}/assign-assembly`;
const bomCreateManufacturer = () => `${bomEndpoints()}/manufacturer/create`;
const bomDeleteManufacturer = (manufacturerName: string) => `${bomEndpoints()}/manufacturer/${manufacturerName}/delete`;
const bomCreateMaterialType = () => `${bomEndpoints()}/material-type/create`;
const bomCreateUnit = () => `${bomEndpoints()}/units/create`;

Expand Down Expand Up @@ -243,6 +244,7 @@ export const apiUrls = {
bomCreateAssembly,
bomAssignAssembly,
bomCreateManufacturer,
bomDeleteManufacturer,
bomCreateMaterialType,
bomCreateUnit,

Expand Down
Loading