fix(setting/ssl): cert files are optional to upload [EE-6139] (#10779)

pull/10843/head
Oscar Zhou 2023-12-13 23:20:09 +13:00 committed by GitHub
parent 4b5ea01456
commit 7408668dbb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 17 deletions

View File

@ -20,8 +20,8 @@ import { useUpdateSSLConfigMutation } from '../useUpdateSSLConfigMutation';
import { useSSLSettings } from '../../queries/useSSLSettings'; import { useSSLSettings } from '../../queries/useSSLSettings';
interface FormValues { interface FormValues {
certFile: File | null; certFile?: File;
keyFile: File | null; keyFile?: File;
forceHTTPS: boolean; forceHTTPS: boolean;
} }
@ -37,8 +37,8 @@ function SSLSettingsPanel() {
} }
const initialValues: FormValues = { const initialValues: FormValues = {
certFile: null, certFile: undefined,
keyFile: null, keyFile: undefined,
forceHTTPS: !settingsQuery.data.httpEnabled, forceHTTPS: !settingsQuery.data.httpEnabled,
}; };
@ -52,7 +52,7 @@ function SSLSettingsPanel() {
validationSchema={validation} validationSchema={validation}
validateOnMount validateOnMount
> >
{({ values, setFieldValue, isValid, errors }) => ( {({ values, setFieldValue, isValid, errors, dirty }) => (
<Form className="form-horizontal"> <Form className="form-horizontal">
<div className="form-group"> <div className="form-group">
<div className="col-sm-12"> <div className="col-sm-12">
@ -92,7 +92,6 @@ function SSLSettingsPanel() {
errors={errors.certFile} errors={errors.certFile}
> >
<FileUploadField <FileUploadField
required={typeof errors.certFile !== 'undefined'}
inputId="ca-cert-field" inputId="ca-cert-field"
name="certFile" name="certFile"
onChange={(file) => setFieldValue('certFile', file)} onChange={(file) => setFieldValue('certFile', file)}
@ -107,7 +106,6 @@ function SSLSettingsPanel() {
errors={errors.keyFile} errors={errors.keyFile}
> >
<FileUploadField <FileUploadField
required={typeof errors.keyFile !== 'undefined'}
inputId="ca-cert-field" inputId="ca-cert-field"
name="keyFile" name="keyFile"
onChange={(file) => setFieldValue('keyFile', file)} onChange={(file) => setFieldValue('keyFile', file)}
@ -119,7 +117,7 @@ function SSLSettingsPanel() {
<div className="col-sm-12"> <div className="col-sm-12">
<LoadingButton <LoadingButton
isLoading={mutation.isLoading || reloadingPage} isLoading={mutation.isLoading || reloadingPage}
disabled={!isValid} disabled={!dirty || !isValid}
loadingText={reloadingPage ? 'Reloading' : 'Saving'} loadingText={reloadingPage ? 'Reloading' : 'Saving'}
className="!ml-0" className="!ml-0"
> >
@ -135,16 +133,12 @@ function SSLSettingsPanel() {
); );
function handleSubmit({ certFile, forceHTTPS, keyFile }: FormValues) { function handleSubmit({ certFile, forceHTTPS, keyFile }: FormValues) {
if (!certFile || !keyFile) {
return;
}
mutation.mutate( mutation.mutate(
{ certFile, httpEnabled: !forceHTTPS, keyFile }, { certFile, httpEnabled: !forceHTTPS, keyFile },
{ {
async onSuccess() { async onSuccess() {
await new Promise((resolve) => { await new Promise((resolve) => {
setTimeout(resolve, 5000); setTimeout(resolve, 10000);
}); });
window.location.reload(); window.location.reload();
setReloadingPage(true); setReloadingPage(true);
@ -156,10 +150,13 @@ function SSLSettingsPanel() {
function validation(): SchemaOf<FormValues> { function validation(): SchemaOf<FormValues> {
return object({ return object({
certFile: withFileExtension(file(), ['pem', 'crt', 'cer', 'cert']).required( certFile: withFileExtension(file(), [
'' 'pem',
), 'crt',
keyFile: withFileExtension(file(), ['pem', 'key']).required(''), 'cer',
'cert',
]).optional(),
keyFile: withFileExtension(file(), ['pem', 'key']).optional(),
forceHTTPS: bool().required(), forceHTTPS: bool().required(),
}); });
} }