Merge branch 'develop' into release/0.0.3

This commit is contained in:
jwu-fisker
2022-08-24 11:06:23 -07:00
7 changed files with 49 additions and 26 deletions

View File

@@ -5825,10 +5825,10 @@ exports[`App Route /tools/certificates/add authenticated 1`] = `
<label
class="MuiFormLabel-root MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated MuiInputLabel-outlined Mui-required Mui-required"
data-shrink="false"
for="vin"
id="vin-label"
for="common_name"
id="common_name-label"
>
VIN
Common Name (VIN)
<span
aria-hidden="true"
class="MuiFormLabel-asterisk MuiInputLabel-asterisk"
@@ -5843,9 +5843,9 @@ exports[`App Route /tools/certificates/add authenticated 1`] = `
<input
aria-invalid="false"
class="MuiInputBase-input MuiOutlinedInput-input"
id="vin"
id="common_name"
maxlength="17"
name="vin"
name="common_name"
required=""
type="text"
value=""
@@ -5858,7 +5858,7 @@ exports[`App Route /tools/certificates/add authenticated 1`] = `
class="PrivateNotchedOutline-legendLabelled-0"
>
<span>
VIN
Common Name (VIN)
 *
</span>
</legend>

View File

@@ -11,9 +11,14 @@ import {
import useStyles from "../../useStyles";
import { CertTypes } from "../../Contexts/CertificateContext";
const getCertTypeLabel = (certtype) => {
if (certtype === CertTypes.Aftersales) return "Service Tool ID";
return "VIN";
};
const CreateForm = ({ onCreate, busy }) => {
const classes = useStyles();
const vinEl = useRef(null);
const commonnameEl = useRef(null);
const [certType, setCertType] = useState(CertTypes.TBOX);
const onSubmit = async (event) => {
@@ -21,7 +26,7 @@ const CreateForm = ({ onCreate, busy }) => {
if (onCreate)
onCreate({
vin: vinEl.current.value,
common_name: commonnameEl.current.value,
type: certType,
});
};
@@ -34,9 +39,9 @@ const CreateForm = ({ onCreate, busy }) => {
<div className={classes.paper}>
<form className={classes.form} noValidate action="{onSubmit}">
<TextField
id="vin"
name="vin"
label="VIN"
id="common_name"
name="common_name"
label={`Common Name (${getCertTypeLabel(certType)})`}
variant="outlined"
margin="normal"
inputProps={{
@@ -44,7 +49,7 @@ const CreateForm = ({ onCreate, busy }) => {
}}
required
fullWidth
inputRef={vinEl}
inputRef={commonnameEl}
/>
<FormLabel id="cert-type-group-label">Type</FormLabel>
<RadioGroup

View File

@@ -6,7 +6,12 @@ import useStyles from "../../useStyles";
const CertMimeType = "application/x-pem-file";
const DownloadCerts = ({ vin, publicCert, privateCert, onChangeView }) => {
const DownloadCerts = ({
commonName,
publicCert,
privateCert,
onChangeView,
}) => {
const classes = useStyles();
const onNewCert = (event) => {
@@ -21,14 +26,14 @@ const DownloadCerts = ({ vin, publicCert, privateCert, onChangeView }) => {
<li>
<DownloadFileLink
data={publicCert}
filename={`${vin}_cert.pem`}
filename={`${commonName}_cert.pem`}
mimetype={CertMimeType}
/>
</li>
<li>
<DownloadFileLink
data={privateCert}
filename={`${vin}_key.pem`}
filename={`${commonName}_key.pem`}
mimetype={CertMimeType}
/>
</li>

View File

@@ -9,16 +9,16 @@ exports[`DownloadCerts Render 1`] = `
<ul>
<li>
<a
download="TESTVIN_cert.pem"
download="undefined_cert.pem"
>
TESTVIN_cert.pem
undefined_cert.pem
</a>
</li>
<li>
<a
download="TESTVIN_key.pem"
download="undefined_key.pem"
>
TESTVIN_key.pem
undefined_key.pem
</a>
</li>
</ul>

View File

@@ -24,7 +24,7 @@ const MainForm = () => {
const [view, setView] = useState(VIEW_FORM);
const [pubCert, setPubCert] = useState(null);
const [privCert, setPrivCert] = useState(null);
const [vin, setVIN] = useState(null);
const [commonName, setCommonName] = useState(null);
useEffect(() => {
setTitle("Create Certificate");
@@ -46,8 +46,8 @@ const MainForm = () => {
setPubCert(result.public_key);
setPrivCert(result.private_key);
setVIN(data.vin);
setMessage(`Created ${data.vin} certificate`);
setCommonName(data.common_name);
setMessage(`Created ${data.common_name} certificate`);
setView(VIEW_DOWNLOAD);
} catch (e) {
setMessage(e.message);
@@ -58,7 +58,7 @@ const MainForm = () => {
const onChangeView = () => {
setPubCert(null);
setPrivCert(null);
setVIN(null);
setCommonName(null);
setView(VIEW_FORM);
};
@@ -66,7 +66,7 @@ const MainForm = () => {
if (view === VIEW_DOWNLOAD)
return (
<DownloadCerts
vin={vin}
commonName={commonName}
publicCert={pubCert}
privateCert={privCert}
onChangeView={onChangeView}

View File

@@ -8,11 +8,12 @@ export const CertTypes = {
TBOX: "TBOX",
ICC: "ICC",
Charging: "Charging",
Aftersales: "Aftersales",
};
const validateCreate = (data) => {
if (!data.type) throw new Error("type is required");
if (!data.vin) throw new Error("vin is required");
if (!data.common_name) throw new Error("common name is required");
};
export const CertificateProvider = ({ children }) => {

View File

@@ -18,6 +18,18 @@ const certificatesAPI = {
})
.then(fetchRespHandler)
.catch(errorHandler),
createAftersales: async (data, token) =>
fetch(`${API_ENDPOINT}/create-aftersales`, {
method: "POST",
headers: Object.assign(
{ "Content-Type": "application/json" },
getAuthHeaderOptions(token)
),
body: JSON.stringify(data),
})
.then(fetchRespHandler)
.catch(errorHandler),
};
export default certificatesAPI;