code cleanup, fix errors

This commit is contained in:
Matthew Penner 2021-09-12 15:56:47 -06:00
parent 8acce201d6
commit 222300ff17
No known key found for this signature in database
GPG key ID: 030E4AB751DC756F
8 changed files with 58 additions and 57 deletions

View file

@ -18,18 +18,18 @@ interface Values {
} }
export default () => { export default () => {
const ref = useRef<Reaptcha>(null); const ref = useRef<Reaptcha | null>(null);
const [ token, setToken ] = useState(''); const [ token, setToken ] = useState('');
const { clearFlashes, addFlash } = useFlash(); const { clearFlashes, addFlash } = useFlash();
const { enabled: recaptchaEnabled, siteKey } = useStoreState(state => state.settings.data!.recaptcha); const { enabled: recaptchaEnabled, siteKey } = useStoreState(state => state.settings.data!.recaptcha);
useEffect(() => { useEffect(() => {
clearFlashes(); clearFlashes(undefined);
}, []); }, []);
const handleSubmission = ({ email }: Values, { setSubmitting, resetForm }: FormikHelpers<Values>) => { const handleSubmission = ({ email }: Values, { setSubmitting, resetForm }: FormikHelpers<Values>) => {
clearFlashes(); clearFlashes(undefined);
// If there is no token in the state yet, request the token and then abort this submit request // If there is no token in the state yet, request the token and then abort this submit request
// since it will be re-submitted when the recaptcha data is returned by the component. // since it will be re-submitted when the recaptcha data is returned by the component.

View file

@ -17,18 +17,18 @@ interface Values {
} }
const LoginContainer = ({ history }: RouteComponentProps) => { const LoginContainer = ({ history }: RouteComponentProps) => {
const ref = useRef<Reaptcha>(null); const ref = useRef<Reaptcha | null>(null);
const [ token, setToken ] = useState(''); const [ token, setToken ] = useState('');
const { clearFlashes, clearAndAddHttpError } = useFlash(); const { clearFlashes, clearAndAddHttpError } = useFlash();
const { enabled: recaptchaEnabled, siteKey } = useStoreState(state => state.settings.data!.recaptcha); const { enabled: recaptchaEnabled, siteKey } = useStoreState(state => state.settings.data!.recaptcha);
useEffect(() => { useEffect(() => {
clearFlashes(); clearFlashes(undefined);
}, []); }, []);
const onSubmit = (values: Values, { setSubmitting }: FormikHelpers<Values>) => { const onSubmit = (values: Values, { setSubmitting }: FormikHelpers<Values>) => {
clearFlashes(); clearFlashes(undefined);
// If there is no token in the state yet, request the token and then abort this submit request // If there is no token in the state yet, request the token and then abort this submit request
// since it will be re-submitted when the recaptcha data is returned by the component. // since it will be re-submitted when the recaptcha data is returned by the component.
@ -54,7 +54,7 @@ const LoginContainer = ({ history }: RouteComponentProps) => {
history.replace('/auth/login/key', { history.replace('/auth/login/key', {
token: response.confirmationToken, token: response.confirmationToken,
publicKey: response.publicKey, publicKey: response.publicKey,
hasTotp: response.methods.includes('totp'), hasTotp: response.methods?.includes('totp'),
}); });
return; return;
} }
@ -63,11 +63,11 @@ const LoginContainer = ({ history }: RouteComponentProps) => {
history.replace('/auth/login/checkpoint', { token: response.confirmationToken }); history.replace('/auth/login/checkpoint', { token: response.confirmationToken });
} }
}) })
.catch(error => { .catch(async (error) => {
console.error(error); console.error(error);
setToken(''); setToken('');
if (ref.current) ref.current.reset(); if (ref.current) await ref.current?.reset();
setSubmitting(false); setSubmitting(false);
clearAndAddHttpError({ error }); clearAndAddHttpError({ error });
@ -111,9 +111,9 @@ const LoginContainer = ({ history }: RouteComponentProps) => {
ref={ref} ref={ref}
size={'invisible'} size={'invisible'}
sitekey={siteKey || '_invalid_key'} sitekey={siteKey || '_invalid_key'}
onVerify={response => { onVerify={async (response) => {
setToken(response); setToken(response);
submitForm(); await submitForm();
}} }}
onExpire={() => { onExpire={() => {
setSubmitting(false); setSubmitting(false);

View file

@ -30,7 +30,7 @@ export default ({ match, location }: RouteComponentProps<{ token: string }>) =>
} }
const submit = ({ password, passwordConfirmation }: Values, { setSubmitting }: FormikHelpers<Values>) => { const submit = ({ password, passwordConfirmation }: Values, { setSubmitting }: FormikHelpers<Values>) => {
clearFlashes(); clearFlashes(undefined);
performPasswordReset(email, { token: match.params.token, password, passwordConfirmation }) performPasswordReset(email, { token: match.params.token, password, passwordConfirmation })
.then(() => { .then(() => {
// @ts-ignore // @ts-ignore

View file

@ -41,7 +41,7 @@ export default ({ database, className }: Props) => {
}); });
const submit = (values: { confirm: string }, { setSubmitting }: FormikHelpers<{ confirm: string }>) => { const submit = (values: { confirm: string }, { setSubmitting }: FormikHelpers<{ confirm: string }>) => {
clearFlashes(); clearFlashes(undefined);
deleteServerDatabase(uuid, database.id) deleteServerDatabase(uuid, database.id)
.then(() => { .then(() => {
setVisible(false); setVisible(false);

View file

@ -22,7 +22,7 @@ export default ({ databaseId, onUpdate }: {
const rotate = () => { const rotate = () => {
setLoading(true); setLoading(true);
clearFlashes(); clearFlashes(undefined);
rotateDatabasePassword(server.uuid, databaseId) rotateDatabasePassword(server.uuid, databaseId)
.then(database => onUpdate(database)) .then(database => onUpdate(database))

View file

@ -38,7 +38,7 @@ export default () => {
}; };
useEffect(() => { useEffect(() => {
clearFlashes(); clearFlashes(undefined);
}, []); }, []);
return ( return (

View file

@ -6,7 +6,7 @@ export interface FlashStore {
items: FlashMessage[]; items: FlashMessage[];
addFlash: Action<FlashStore, FlashMessage>; addFlash: Action<FlashStore, FlashMessage>;
addError: Action<FlashStore, { message: string; key?: string }>; addError: Action<FlashStore, { message: string; key?: string }>;
clearAndAddHttpError: Action<FlashStore, { error: any, key?: string }>; clearAndAddHttpError: Action<FlashStore, { error: any; key?: string }>;
clearFlashes: Action<FlashStore, string | void>; clearFlashes: Action<FlashStore, string | void>;
} }
@ -29,8 +29,8 @@ const flashes: FlashStore = {
state.items.push({ type: 'error', title: 'Error', ...payload }); state.items.push({ type: 'error', title: 'Error', ...payload });
}), }),
clearAndAddHttpError: action((state, { key, error }) => { clearAndAddHttpError: action((state, payload) => {
state.items = [ { type: 'error', title: 'Error', key, message: httpErrorToHuman(error) } ]; state.items = [ { type: 'error', title: 'Error', key: payload.key, message: httpErrorToHuman(payload.error) } ];
}), }),
clearFlashes: action((state, payload) => { clearFlashes: action((state, payload) => {

View file

@ -1,44 +1,45 @@
{ {
"compilerOptions": { "compilerOptions": {
"target": "es2015", "target": "ES2020",
"module": "es2020", "module": "ES2020",
"jsx": "react", "jsx": "react",
"moduleResolution": "node", "moduleResolution": "Node",
"lib": [ "lib": [
"es2015", "ES2020",
"dom" "DOM",
], "DOM.Iterable"
"strict": true, ],
"noEmit": true, "strict": true,
"sourceMap": true, "noEmit": true,
"noImplicitReturns": true, "sourceMap": true,
"skipLibCheck": true, "noImplicitReturns": true,
"skipDefaultLibCheck": true, "skipLibCheck": true,
"esModuleInterop": true, "skipDefaultLibCheck": true,
"allowSyntheticDefaultImports": true, "esModuleInterop": true,
"baseUrl": ".", "allowSyntheticDefaultImports": true,
"importsNotUsedAsValues": "preserve", "baseUrl": ".",
"paths": { "importsNotUsedAsValues": "preserve",
"@/*": [ "paths": {
"./resources/scripts/*" "@/*": [
], "./resources/scripts/*"
"@feature/*": [ ],
"./resources/scripts/components/server/features/*" "@feature/*": [
] "./resources/scripts/components/server/features/*"
]
},
"plugins": [
{
"name": "typescript-plugin-tw-template"
}
],
"typeRoots": [
"node_modules/@types"
]
}, },
"plugins": [ "include": [
{ "./resources/scripts/**/*"
"name": "typescript-plugin-tw-template"
}
], ],
"typeRoots": [ "exclude": [
"node_modules/@types" "/node_modules/"
] ]
},
"include": [
"./resources/scripts/**/*"
],
"exclude": [
"/node_modules/"
]
} }