-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
) * feature(OH2-303): Implement operation create, update and delete operations * refactor: Rename admin operation paths * fix: Fix operation delete i18n labels and refactor delete status --------- Co-authored-by: SteveGT96 <[email protected]>
- Loading branch information
Showing
21 changed files
with
832 additions
and
68 deletions.
There are no files selected for viewing
37 changes: 30 additions & 7 deletions
37
src/components/accessories/admin/operations/Operations.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 |
---|---|---|
@@ -1,31 +1,54 @@ | ||
import React, { useEffect } from "react"; | ||
import classes from "./Operations.module.scss"; | ||
import { useDispatch } from "react-redux"; | ||
import { | ||
deleteOperation, | ||
getOperations, | ||
} from "../../../../state/operations/actions"; | ||
import { OperationDTO } from "../../../../generated"; | ||
import OperationTable from "./operationTable"; | ||
import { getOperations } from "../../../../state/operations/actions"; | ||
import { getOperationTypes } from "../../../../state/operationTypes/actions"; | ||
import Button from "../../button/Button"; | ||
import { useNavigate } from "react-router"; | ||
import { useTranslation } from "react-i18next"; | ||
import { PATHS } from "../../../../consts"; | ||
|
||
export const Operations = () => { | ||
const navigate = useNavigate(); | ||
const dispatch = useDispatch(); | ||
const { t } = useTranslation(); | ||
|
||
useEffect(() => { | ||
dispatch(getOperations()); | ||
dispatch(getOperationTypes()); | ||
}, [dispatch]); | ||
|
||
const handleEdit = (row: OperationDTO) => { | ||
// TODO | ||
navigate(PATHS.admin_operations_edit.replace("#id", row.code!), { | ||
state: row, | ||
}); | ||
}; | ||
|
||
const handleDelete = (row: OperationDTO) => { | ||
// TODO | ||
dispatch(deleteOperation(row.code ?? "")); | ||
}; | ||
|
||
return ( | ||
<div className={classes.operations}> | ||
<div className={classes.actions}></div> | ||
<OperationTable onEdit={handleEdit} onDelete={handleDelete} /> | ||
<OperationTable | ||
onEdit={handleEdit} | ||
onDelete={handleDelete} | ||
headerActions={ | ||
<Button | ||
onClick={() => { | ||
navigate(PATHS.admin_operations_new); | ||
}} | ||
type="button" | ||
variant="contained" | ||
color="primary" | ||
> | ||
{t("operation.addOperation")} | ||
</Button> | ||
} | ||
/> | ||
</div> | ||
); | ||
}; |
40 changes: 40 additions & 0 deletions
40
src/components/accessories/admin/operations/editOperation/EditOperation.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 { useTranslation } from "react-i18next"; | ||
import OperationForm from "../operationForm/OperationForm"; | ||
import React from "react"; | ||
import { getInitialFields } from "../operationForm/consts"; | ||
import { useDispatch, useSelector } from "react-redux"; | ||
import { OperationDTO } from "../../../../../generated"; | ||
import { ApiResponse } from "../../../../../state/types"; | ||
import { updateOperation } from "../../../../../state/operations/actions"; | ||
import { IState } from "../../../../../types"; | ||
import { Navigate, useLocation, useParams } from "react-router"; | ||
import { PATHS } from "../../../../../consts"; | ||
|
||
export const EditOperation = () => { | ||
const dispatch = useDispatch(); | ||
const { t } = useTranslation(); | ||
const { state }: { state: OperationDTO | undefined } = useLocation(); | ||
const { id } = useParams(); | ||
const update = useSelector<IState, ApiResponse<OperationDTO>>( | ||
(state) => state.operations.update | ||
); | ||
|
||
const handleSubmit = (value: OperationDTO) => { | ||
dispatch(updateOperation({ code: id ?? "", operationDTO: value })); | ||
}; | ||
|
||
if (state?.code !== id) { | ||
return <Navigate to={PATHS.admin_operations} />; | ||
} | ||
|
||
return ( | ||
<OperationForm | ||
creationMode={false} | ||
onSubmit={handleSubmit} | ||
isLoading={!!update.isLoading} | ||
resetButtonLabel={t("common.cancel")} | ||
submitButtonLabel={t("operation.updateOperation")} | ||
fields={getInitialFields(state)} | ||
/> | ||
); | ||
}; |
1 change: 1 addition & 0 deletions
1
src/components/accessories/admin/operations/editOperation/index.ts
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 @@ | ||
export * from "./EditOperation"; |
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 |
---|---|---|
@@ -1 +1,3 @@ | ||
export * from "./Operations"; | ||
export * from "./newOperation"; | ||
export * from "./editOperation"; |
32 changes: 32 additions & 0 deletions
32
src/components/accessories/admin/operations/newOperation/NewOperation.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,32 @@ | ||
import { useTranslation } from "react-i18next"; | ||
import OperationForm from "../operationForm/OperationForm"; | ||
import React from "react"; | ||
import { getInitialFields } from "../operationForm/consts"; | ||
import { useDispatch, useSelector } from "react-redux"; | ||
import { OperationDTO } from "../../../../../generated"; | ||
import { createOperation } from "../../../../../state/operations/actions"; | ||
import { IState } from "../../../../../types"; | ||
import { ApiResponse } from "../../../../../state/types"; | ||
|
||
export const NewOperation = () => { | ||
const dispatch = useDispatch(); | ||
const { t } = useTranslation(); | ||
const create = useSelector<IState, ApiResponse<OperationDTO>>( | ||
(state) => state.operations.create | ||
); | ||
|
||
const handleSubmit = (value: OperationDTO) => { | ||
dispatch(createOperation(value)); | ||
}; | ||
|
||
return ( | ||
<OperationForm | ||
creationMode | ||
onSubmit={handleSubmit} | ||
isLoading={!!create.isLoading} | ||
resetButtonLabel={t("common.cancel")} | ||
submitButtonLabel={t("operation.saveOperation")} | ||
fields={getInitialFields(undefined)} | ||
/> | ||
); | ||
}; |
1 change: 1 addition & 0 deletions
1
src/components/accessories/admin/operations/newOperation/index.ts
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 @@ | ||
export * from "./NewOperation"; |
Oops, something went wrong.