Merge branch 'develop' into release/0.0.3
This commit is contained in:
@@ -5825,10 +5825,10 @@ exports[`App Route /tools/certificates/add authenticated 1`] = `
|
|||||||
<label
|
<label
|
||||||
class="MuiFormLabel-root MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated MuiInputLabel-outlined Mui-required Mui-required"
|
class="MuiFormLabel-root MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated MuiInputLabel-outlined Mui-required Mui-required"
|
||||||
data-shrink="false"
|
data-shrink="false"
|
||||||
for="vin"
|
for="common_name"
|
||||||
id="vin-label"
|
id="common_name-label"
|
||||||
>
|
>
|
||||||
VIN
|
Common Name (VIN)
|
||||||
<span
|
<span
|
||||||
aria-hidden="true"
|
aria-hidden="true"
|
||||||
class="MuiFormLabel-asterisk MuiInputLabel-asterisk"
|
class="MuiFormLabel-asterisk MuiInputLabel-asterisk"
|
||||||
@@ -5843,9 +5843,9 @@ exports[`App Route /tools/certificates/add authenticated 1`] = `
|
|||||||
<input
|
<input
|
||||||
aria-invalid="false"
|
aria-invalid="false"
|
||||||
class="MuiInputBase-input MuiOutlinedInput-input"
|
class="MuiInputBase-input MuiOutlinedInput-input"
|
||||||
id="vin"
|
id="common_name"
|
||||||
maxlength="17"
|
maxlength="17"
|
||||||
name="vin"
|
name="common_name"
|
||||||
required=""
|
required=""
|
||||||
type="text"
|
type="text"
|
||||||
value=""
|
value=""
|
||||||
@@ -5858,7 +5858,7 @@ exports[`App Route /tools/certificates/add authenticated 1`] = `
|
|||||||
class="PrivateNotchedOutline-legendLabelled-0"
|
class="PrivateNotchedOutline-legendLabelled-0"
|
||||||
>
|
>
|
||||||
<span>
|
<span>
|
||||||
VIN
|
Common Name (VIN)
|
||||||
*
|
*
|
||||||
</span>
|
</span>
|
||||||
</legend>
|
</legend>
|
||||||
|
|||||||
@@ -11,9 +11,14 @@ import {
|
|||||||
import useStyles from "../../useStyles";
|
import useStyles from "../../useStyles";
|
||||||
import { CertTypes } from "../../Contexts/CertificateContext";
|
import { CertTypes } from "../../Contexts/CertificateContext";
|
||||||
|
|
||||||
|
const getCertTypeLabel = (certtype) => {
|
||||||
|
if (certtype === CertTypes.Aftersales) return "Service Tool ID";
|
||||||
|
return "VIN";
|
||||||
|
};
|
||||||
|
|
||||||
const CreateForm = ({ onCreate, busy }) => {
|
const CreateForm = ({ onCreate, busy }) => {
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
const vinEl = useRef(null);
|
const commonnameEl = useRef(null);
|
||||||
const [certType, setCertType] = useState(CertTypes.TBOX);
|
const [certType, setCertType] = useState(CertTypes.TBOX);
|
||||||
|
|
||||||
const onSubmit = async (event) => {
|
const onSubmit = async (event) => {
|
||||||
@@ -21,7 +26,7 @@ const CreateForm = ({ onCreate, busy }) => {
|
|||||||
|
|
||||||
if (onCreate)
|
if (onCreate)
|
||||||
onCreate({
|
onCreate({
|
||||||
vin: vinEl.current.value,
|
common_name: commonnameEl.current.value,
|
||||||
type: certType,
|
type: certType,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -34,9 +39,9 @@ const CreateForm = ({ onCreate, busy }) => {
|
|||||||
<div className={classes.paper}>
|
<div className={classes.paper}>
|
||||||
<form className={classes.form} noValidate action="{onSubmit}">
|
<form className={classes.form} noValidate action="{onSubmit}">
|
||||||
<TextField
|
<TextField
|
||||||
id="vin"
|
id="common_name"
|
||||||
name="vin"
|
name="common_name"
|
||||||
label="VIN"
|
label={`Common Name (${getCertTypeLabel(certType)})`}
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
margin="normal"
|
margin="normal"
|
||||||
inputProps={{
|
inputProps={{
|
||||||
@@ -44,7 +49,7 @@ const CreateForm = ({ onCreate, busy }) => {
|
|||||||
}}
|
}}
|
||||||
required
|
required
|
||||||
fullWidth
|
fullWidth
|
||||||
inputRef={vinEl}
|
inputRef={commonnameEl}
|
||||||
/>
|
/>
|
||||||
<FormLabel id="cert-type-group-label">Type</FormLabel>
|
<FormLabel id="cert-type-group-label">Type</FormLabel>
|
||||||
<RadioGroup
|
<RadioGroup
|
||||||
|
|||||||
@@ -6,7 +6,12 @@ import useStyles from "../../useStyles";
|
|||||||
|
|
||||||
const CertMimeType = "application/x-pem-file";
|
const CertMimeType = "application/x-pem-file";
|
||||||
|
|
||||||
const DownloadCerts = ({ vin, publicCert, privateCert, onChangeView }) => {
|
const DownloadCerts = ({
|
||||||
|
commonName,
|
||||||
|
publicCert,
|
||||||
|
privateCert,
|
||||||
|
onChangeView,
|
||||||
|
}) => {
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
|
|
||||||
const onNewCert = (event) => {
|
const onNewCert = (event) => {
|
||||||
@@ -21,14 +26,14 @@ const DownloadCerts = ({ vin, publicCert, privateCert, onChangeView }) => {
|
|||||||
<li>
|
<li>
|
||||||
<DownloadFileLink
|
<DownloadFileLink
|
||||||
data={publicCert}
|
data={publicCert}
|
||||||
filename={`${vin}_cert.pem`}
|
filename={`${commonName}_cert.pem`}
|
||||||
mimetype={CertMimeType}
|
mimetype={CertMimeType}
|
||||||
/>
|
/>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<DownloadFileLink
|
<DownloadFileLink
|
||||||
data={privateCert}
|
data={privateCert}
|
||||||
filename={`${vin}_key.pem`}
|
filename={`${commonName}_key.pem`}
|
||||||
mimetype={CertMimeType}
|
mimetype={CertMimeType}
|
||||||
/>
|
/>
|
||||||
</li>
|
</li>
|
||||||
|
|||||||
@@ -9,16 +9,16 @@ exports[`DownloadCerts Render 1`] = `
|
|||||||
<ul>
|
<ul>
|
||||||
<li>
|
<li>
|
||||||
<a
|
<a
|
||||||
download="TESTVIN_cert.pem"
|
download="undefined_cert.pem"
|
||||||
>
|
>
|
||||||
TESTVIN_cert.pem
|
undefined_cert.pem
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<a
|
<a
|
||||||
download="TESTVIN_key.pem"
|
download="undefined_key.pem"
|
||||||
>
|
>
|
||||||
TESTVIN_key.pem
|
undefined_key.pem
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ const MainForm = () => {
|
|||||||
const [view, setView] = useState(VIEW_FORM);
|
const [view, setView] = useState(VIEW_FORM);
|
||||||
const [pubCert, setPubCert] = useState(null);
|
const [pubCert, setPubCert] = useState(null);
|
||||||
const [privCert, setPrivCert] = useState(null);
|
const [privCert, setPrivCert] = useState(null);
|
||||||
const [vin, setVIN] = useState(null);
|
const [commonName, setCommonName] = useState(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setTitle("Create Certificate");
|
setTitle("Create Certificate");
|
||||||
@@ -46,19 +46,19 @@ const MainForm = () => {
|
|||||||
|
|
||||||
setPubCert(result.public_key);
|
setPubCert(result.public_key);
|
||||||
setPrivCert(result.private_key);
|
setPrivCert(result.private_key);
|
||||||
setVIN(data.vin);
|
setCommonName(data.common_name);
|
||||||
setMessage(`Created ${data.vin} certificate`);
|
setMessage(`Created ${data.common_name} certificate`);
|
||||||
setView(VIEW_DOWNLOAD);
|
setView(VIEW_DOWNLOAD);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
setMessage(e.message);
|
setMessage(e.message);
|
||||||
logger.warn(e.stack);
|
logger.warn(e.stack);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const onChangeView = () => {
|
const onChangeView = () => {
|
||||||
setPubCert(null);
|
setPubCert(null);
|
||||||
setPrivCert(null);
|
setPrivCert(null);
|
||||||
setVIN(null);
|
setCommonName(null);
|
||||||
|
|
||||||
setView(VIEW_FORM);
|
setView(VIEW_FORM);
|
||||||
};
|
};
|
||||||
@@ -66,7 +66,7 @@ const MainForm = () => {
|
|||||||
if (view === VIEW_DOWNLOAD)
|
if (view === VIEW_DOWNLOAD)
|
||||||
return (
|
return (
|
||||||
<DownloadCerts
|
<DownloadCerts
|
||||||
vin={vin}
|
commonName={commonName}
|
||||||
publicCert={pubCert}
|
publicCert={pubCert}
|
||||||
privateCert={privCert}
|
privateCert={privCert}
|
||||||
onChangeView={onChangeView}
|
onChangeView={onChangeView}
|
||||||
|
|||||||
@@ -8,11 +8,12 @@ export const CertTypes = {
|
|||||||
TBOX: "TBOX",
|
TBOX: "TBOX",
|
||||||
ICC: "ICC",
|
ICC: "ICC",
|
||||||
Charging: "Charging",
|
Charging: "Charging",
|
||||||
|
Aftersales: "Aftersales",
|
||||||
};
|
};
|
||||||
|
|
||||||
const validateCreate = (data) => {
|
const validateCreate = (data) => {
|
||||||
if (!data.type) throw new Error("type is required");
|
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 }) => {
|
export const CertificateProvider = ({ children }) => {
|
||||||
|
|||||||
@@ -18,6 +18,18 @@ const certificatesAPI = {
|
|||||||
})
|
})
|
||||||
.then(fetchRespHandler)
|
.then(fetchRespHandler)
|
||||||
.catch(errorHandler),
|
.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;
|
export default certificatesAPI;
|
||||||
|
|||||||
Reference in New Issue
Block a user