CEC-2075 Remove supplier active directory id (#167)
* CEC-2075 Remove supplier oid * Clean up
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import React, { useContext, useEffect, useState } from "react";
|
||||
import api from "../../services/suppliersAPI";
|
||||
import { LocalDateTimeString } from "../../utils/dates";
|
||||
|
||||
import {
|
||||
validateSupplier,
|
||||
@@ -12,26 +13,26 @@ const SupplierDetailsContext = React.createContext();
|
||||
export const SupplierDetailsProvider = ({ children }) => {
|
||||
const { getSuppliers, suppliers } = useSupplierContext();
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [id, setID] = useState("");
|
||||
const [contact, setContact] = useState("");
|
||||
const [company, setCompany] = useState("");
|
||||
const [address, setAddress] = useState("");
|
||||
const [phone, setPhone] = useState("");
|
||||
const [program, setProgram] = useState("");
|
||||
const [ecus, setECUs] = useState("");
|
||||
const [activated, setActivated] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!suppliers || suppliers.length === 0) return;
|
||||
|
||||
const supplier = suppliers[0];
|
||||
|
||||
setID(supplier?.id || "");
|
||||
setContact(supplier?.contact || "");
|
||||
setCompany(supplier?.company || "");
|
||||
setAddress(supplier?.address || "");
|
||||
setPhone(supplier?.telephone || "");
|
||||
setProgram(supplier?.program || "");
|
||||
setECUs(supplier?.ecus.join(",") || "");
|
||||
setActivated(LocalDateTimeString(supplier?.activated));
|
||||
}, [suppliers]);
|
||||
|
||||
const getSupplier = async (email, token) => {
|
||||
@@ -55,7 +56,6 @@ export const SupplierDetailsProvider = ({ children }) => {
|
||||
};
|
||||
|
||||
const formData = (email) => ({
|
||||
id,
|
||||
contact,
|
||||
company,
|
||||
address,
|
||||
@@ -65,6 +65,25 @@ export const SupplierDetailsProvider = ({ children }) => {
|
||||
ecus: getECUs(),
|
||||
});
|
||||
|
||||
const activateSupplier = async (email, token) => {
|
||||
try {
|
||||
setBusy(true);
|
||||
validateEmail(email);
|
||||
|
||||
const result = await api.activateSupplier(email, token);
|
||||
if (result.error)
|
||||
throw new Error(`Activate supplier error. ${result.message}`);
|
||||
|
||||
setActivated(
|
||||
LocalDateTimeString(result.activate) || new Date().toDateString()
|
||||
);
|
||||
|
||||
return result;
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
|
||||
const updateSupplier = async (email, token) => {
|
||||
try {
|
||||
const supplier = formData(email);
|
||||
@@ -80,14 +99,15 @@ export const SupplierDetailsProvider = ({ children }) => {
|
||||
}
|
||||
};
|
||||
|
||||
const deleteSupplier = async (vin, token) => {
|
||||
const deleteSupplier = async (email, token) => {
|
||||
try {
|
||||
setBusy(true);
|
||||
validateEmail(vin);
|
||||
validateEmail(email);
|
||||
|
||||
const result = await api.deleteSupplier(vin, token);
|
||||
const result = await api.deleteSupplier(email, token);
|
||||
if (result.error)
|
||||
throw new Error(`Delete supplier error. ${result.message}`);
|
||||
|
||||
return result;
|
||||
} finally {
|
||||
setBusy(false);
|
||||
@@ -97,18 +117,18 @@ export const SupplierDetailsProvider = ({ children }) => {
|
||||
return (
|
||||
<SupplierDetailsContext.Provider
|
||||
value={{
|
||||
activated,
|
||||
busy,
|
||||
id,
|
||||
contact,
|
||||
company,
|
||||
address,
|
||||
phone,
|
||||
program,
|
||||
ecus,
|
||||
activateSupplier,
|
||||
deleteSupplier,
|
||||
getSupplier,
|
||||
updateSupplier,
|
||||
setID,
|
||||
setContact,
|
||||
setCompany,
|
||||
setAddress,
|
||||
|
||||
Reference in New Issue
Block a user