-
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:Operation types admin * fix:Fix type selector malfunction * remove unused import
- Loading branch information
Showing
40 changed files
with
1,071 additions
and
113 deletions.
There are no files selected for viewing
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
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
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
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,2 @@ | ||
export * from "./vaccines"; | ||
export * from "./operations"; |
67 changes: 67 additions & 0 deletions
67
src/components/accessories/admin/types/components/operations/OperationTypes.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,67 @@ | ||
import React, { useEffect } from "react"; | ||
import { useTranslation } from "react-i18next"; | ||
import { useDispatch } from "react-redux"; | ||
import { useNavigate } from "react-router"; | ||
import { | ||
deleteOperationType, | ||
deleteOperationTypeReset, | ||
getOperationTypes, | ||
} from "../../../../../../state/types/operations/actions"; | ||
import { OperationTypeDTO } from "../../../../../../generated"; | ||
import { PATHS } from "../../../../../../consts"; | ||
import OperationTypesTable from "./operationTypesTable"; | ||
import Button from "../../../../button/Button"; | ||
import "./styles.scss"; | ||
import { setTypeMode } from "../../../../../../state/types/config"; | ||
|
||
const OperationTypes = () => { | ||
const navigate = useNavigate(); | ||
const dispatch = useDispatch(); | ||
|
||
useEffect(() => { | ||
dispatch(getOperationTypes()); | ||
dispatch(setTypeMode("manage")); | ||
|
||
return () => { | ||
dispatch(deleteOperationTypeReset()); | ||
}; | ||
}, [dispatch]); | ||
|
||
const handleEdit = (row: OperationTypeDTO) => { | ||
navigate(PATHS.admin_operations_types_edit.replace(":code", row.code!), { | ||
state: row, | ||
}); | ||
}; | ||
|
||
const handleDelete = (row: OperationTypeDTO) => { | ||
dispatch(deleteOperationType(row.code ?? "")); | ||
}; | ||
|
||
const { t } = useTranslation(); | ||
return ( | ||
<> | ||
<h3>{t("operationTypes.title")}</h3> | ||
|
||
<div className="operationTypes"> | ||
<OperationTypesTable | ||
onEdit={handleEdit} | ||
onDelete={handleDelete} | ||
headerActions={ | ||
<Button | ||
onClick={() => { | ||
navigate("./new"); | ||
}} | ||
type="button" | ||
variant="contained" | ||
color="primary" | ||
> | ||
{t("operationTypes.addOperationType")} | ||
</Button> | ||
} | ||
/> | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
export default OperationTypes; |
49 changes: 49 additions & 0 deletions
49
...nts/accessories/admin/types/components/operations/editOperationType/EditOperationType.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,49 @@ | ||
import { useTranslation } from "react-i18next"; | ||
import React, { useEffect } from "react"; | ||
import { useDispatch, useSelector } from "react-redux"; | ||
import { Navigate, useLocation, useParams } from "react-router"; | ||
import { OperationTypeDTO } from "../../../../../../../generated"; | ||
import { IState } from "../../../../../../../types"; | ||
import { ApiResponse } from "../../../../../../../state/types"; | ||
import { updateOperationType } from "../../../../../../../state/types/operations/actions"; | ||
import { PATHS } from "../../../../../../../consts"; | ||
import { setTypeMode } from "../../../../../../../state/types/config"; | ||
import "./styles.scss"; | ||
import OperationTypeForm from "../operationTypesForm/OperationTypeForm"; | ||
import { getInitialFields } from "../operationTypesForm/consts"; | ||
|
||
export const EditOperationType = () => { | ||
const dispatch = useDispatch(); | ||
const { t } = useTranslation(); | ||
const { state }: { state: OperationTypeDTO | undefined } = useLocation(); | ||
const { code } = useParams(); | ||
const update = useSelector<IState, ApiResponse<OperationTypeDTO>>( | ||
(state) => state.types.operations.update | ||
); | ||
|
||
const handleSubmit = (code: string, value: OperationTypeDTO) => { | ||
dispatch(updateOperationType(code, value)); | ||
}; | ||
|
||
useEffect(() => { | ||
dispatch(setTypeMode("edit")); | ||
}); | ||
|
||
if (state?.code !== code) { | ||
return <Navigate to={PATHS.admin_operations_types} />; | ||
} | ||
|
||
return ( | ||
<div className="editOperationType"> | ||
<h3 className="title">{t("operationTypes.editOperationType")}</h3> | ||
<OperationTypeForm | ||
creationMode={false} | ||
onSubmit={handleSubmit} | ||
isLoading={!!update.isLoading} | ||
resetButtonLabel={t("common.cancel")} | ||
submitButtonLabel={t("operationTypes.updateOperationType")} | ||
fields={getInitialFields(state)} | ||
/> | ||
</div> | ||
); | ||
}; |
1 change: 1 addition & 0 deletions
1
src/components/accessories/admin/types/components/operations/editOperationType/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 "./EditOperationType"; |
5 changes: 5 additions & 0 deletions
5
src/components/accessories/admin/types/components/operations/editOperationType/styles.scss
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,5 @@ | ||
.editOperationType { | ||
.title { | ||
margin-bottom: 10px; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/components/accessories/admin/types/components/operations/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,7 @@ | ||
import OperationTypes from "./OperationTypes"; | ||
|
||
export default OperationTypes; | ||
export * from "./editOperationType"; | ||
export * from "./newOperationType"; | ||
export * from "./operationTypesForm"; | ||
export * from "./operationTypesTable"; |
41 changes: 41 additions & 0 deletions
41
...nents/accessories/admin/types/components/operations/newOperationType/NewOperationType.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,41 @@ | ||
import { useTranslation } from "react-i18next"; | ||
import React, { useEffect } from "react"; | ||
import { useDispatch, useSelector } from "react-redux"; | ||
import { IState } from "../../../../../../../types"; | ||
import { ApiResponse } from "../../../../../../../state/types"; | ||
import { OperationTypeDTO } from "../../../../../../../generated"; | ||
import { createOperationType } from "../../../../../../../state/types/operations/actions"; | ||
import { setTypeMode } from "../../../../../../../state/types/config"; | ||
import "./styles.scss"; | ||
import OperationTypeForm from "../operationTypesForm/OperationTypeForm"; | ||
import { getInitialFields } from "../operationTypesForm/consts"; | ||
|
||
export const NewOperationType = () => { | ||
const dispatch = useDispatch(); | ||
const { t } = useTranslation(); | ||
const create = useSelector<IState, ApiResponse<OperationTypeDTO>>( | ||
(state) => state.types.operations.create | ||
); | ||
|
||
useEffect(() => { | ||
dispatch(setTypeMode("edit")); | ||
}); | ||
|
||
const handleSubmit = (code: string, value: OperationTypeDTO) => { | ||
dispatch(createOperationType(value)); | ||
}; | ||
|
||
return ( | ||
<div className="newOperationType"> | ||
<h3 className="title">{t("operationTypes.addOperationType")}</h3> | ||
<OperationTypeForm | ||
creationMode | ||
onSubmit={handleSubmit} | ||
isLoading={!!create.isLoading} | ||
resetButtonLabel={t("common.cancel")} | ||
submitButtonLabel={t("operationTypes.saveOperationTypes")} | ||
fields={getInitialFields(undefined)} | ||
/> | ||
</div> | ||
); | ||
}; |
1 change: 1 addition & 0 deletions
1
src/components/accessories/admin/types/components/operations/newOperationType/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 "./NewOperationType"; |
5 changes: 5 additions & 0 deletions
5
src/components/accessories/admin/types/components/operations/newOperationType/styles.scss
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,5 @@ | ||
.newOperationType { | ||
.title { | ||
margin-bottom: 10px; | ||
} | ||
} |
Oops, something went wrong.