CEC-749 Generate cert UI (#141)

* Add Create Certificate page

* Tests

* Update permission check

* Use Azure
This commit is contained in:
John Wu
2022-04-18 16:50:51 -07:00
committed by GitHub
parent 81aeedc521
commit 56bef0c34d
28 changed files with 2449 additions and 289 deletions

View File

@@ -0,0 +1,50 @@
import React, { useContext, useState } from "react";
import api from "../../services/certificatesAPI";
const CertificateContext = React.createContext();
export const CertTypes = {
TREX: "TREX",
HMI: "HMI",
Charging: "CHARGE",
};
const validateCreate = (data) => {
if (!data.type) throw new Error("type is required");
if (!data.vin) throw new Error("vin is required");
};
export const CertificateProvider = ({ children }) => {
const [busy, setBusy] = useState(false);
const createCert = async (data, token) => {
try {
setBusy(true);
validateCreate(data);
const result = await api.create(data, token);
if (result.error) {
throw new Error(`Create certificate error. ${result.message}`);
}
return result;
} finally {
setBusy(false);
}
};
return (
<CertificateContext.Provider
value={{
busy,
createCert,
}}
>
{children}
</CertificateContext.Provider>
);
};
export const useCertificateContext = () => useContext(CertificateContext);