-
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-305 | Supplier creation and edit * fix:Rename route paths
- Loading branch information
Showing
21 changed files
with
758 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,37 @@ | ||
import React from "react"; | ||
|
||
import SuppliersTable from "./suppliersTable"; | ||
import { useNavigate } from "react-router"; | ||
import { useTranslation } from "react-i18next"; | ||
import { SupplierDTO } from "../../../../generated"; | ||
import { PATHS } from "../../../../consts"; | ||
import Button from "../../button/Button"; | ||
|
||
export const Suppliers = () => { | ||
return <SuppliersTable />; | ||
const navigate = useNavigate(); | ||
const { t } = useTranslation(); | ||
|
||
const handleEdit = (row: SupplierDTO) => { | ||
navigate(PATHS.admin_suppliers_edit.replace(":id", `${row.supId}`), { | ||
state: row, | ||
}); | ||
}; | ||
|
||
return ( | ||
<SuppliersTable | ||
onEdit={handleEdit} | ||
headerActions={ | ||
<Button | ||
onClick={() => { | ||
navigate(PATHS.admin_suppliers_new); | ||
}} | ||
type="button" | ||
variant="contained" | ||
color="primary" | ||
> | ||
{t("supplier.addSupplier")} | ||
</Button> | ||
} | ||
/> | ||
); | ||
}; |
43 changes: 43 additions & 0 deletions
43
src/components/accessories/admin/suppliers/editSupplier/EditSupplier.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,43 @@ | ||
import React, { useEffect } from "react"; | ||
import { useTranslation } from "react-i18next"; | ||
import { useDispatch, useSelector } from "react-redux"; | ||
import { SupplierDTO } from "../../../../../generated"; | ||
import { ApiResponse } from "../../../../../state/types"; | ||
import { IState } from "../../../../../types"; | ||
import { useLocation, useNavigate, useParams } from "react-router"; | ||
import { PATHS } from "../../../../../consts"; | ||
import SupplierForm from "../supplierForm/SupplierForm"; | ||
import { getInitialFields } from "../supplierForm/consts"; | ||
import { updateSupplier } from "../../../../../state/suppliers/actions"; | ||
|
||
export const EditSupplier = () => { | ||
const dispatch = useDispatch(); | ||
const { t } = useTranslation(); | ||
const { state }: { state: SupplierDTO | undefined } = useLocation(); | ||
const { id } = useParams(); | ||
const update = useSelector<IState, ApiResponse<SupplierDTO>>( | ||
(state) => state.suppliers.update | ||
); | ||
const navigate = useNavigate(); | ||
|
||
const handleSubmit = (value: SupplierDTO) => { | ||
dispatch(updateSupplier(value)); | ||
}; | ||
|
||
useEffect(() => { | ||
if (state?.supId !== Number(id)) { | ||
navigate(PATHS.admin_suppliers); | ||
} | ||
}, [id, state]); | ||
|
||
return ( | ||
<SupplierForm | ||
creationMode={false} | ||
onSubmit={handleSubmit} | ||
isLoading={!!update.isLoading} | ||
resetButtonLabel={t("common.cancel")} | ||
submitButtonLabel={t("supplier.updateSupplier")} | ||
fields={getInitialFields(state)} | ||
/> | ||
); | ||
}; |
1 change: 1 addition & 0 deletions
1
src/components/accessories/admin/suppliers/editSupplier/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 "./EditSupplier"; |
32 changes: 32 additions & 0 deletions
32
src/components/accessories/admin/suppliers/newSupplier/NewSupplier.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 React from "react"; | ||
import { useDispatch, useSelector } from "react-redux"; | ||
import { SupplierDTO } from "../../../../../generated"; | ||
import { IState } from "../../../../../types"; | ||
import { ApiResponse } from "../../../../../state/types"; | ||
import SupplierForm from "../supplierForm/SupplierForm"; | ||
import { getInitialFields } from "../supplierForm/consts"; | ||
import { createSupplier } from "../../../../../state/suppliers/actions"; | ||
|
||
export const NewSupplier = () => { | ||
const dispatch = useDispatch(); | ||
const { t } = useTranslation(); | ||
const create = useSelector<IState, ApiResponse<SupplierDTO>>( | ||
(state) => state.suppliers.create | ||
); | ||
|
||
const handleSubmit = (value: SupplierDTO) => { | ||
dispatch(createSupplier(value)); | ||
}; | ||
|
||
return ( | ||
<SupplierForm | ||
creationMode | ||
onSubmit={handleSubmit} | ||
isLoading={!!create.isLoading} | ||
resetButtonLabel={t("common.cancel")} | ||
submitButtonLabel={t("supplier.saveSupplier")} | ||
fields={getInitialFields(undefined)} | ||
/> | ||
); | ||
}; |
1 change: 1 addition & 0 deletions
1
src/components/accessories/admin/suppliers/newSupplier/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 "./NewSupplier"; |
Oops, something went wrong.