-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature] Add tacktracker zip download capability #34
Changes from all commits
2eaf1f3
905ba2e
2cd8df4
f6d2521
fd12da9
3069281
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import { useMemo } from "react"; | ||
import { useContext, useState } from "react"; | ||
import { useMemo, useEffect, useContext, useState } from "react"; | ||
import { useLocation, useNavigate, Link } from "react-router-dom"; | ||
import { UserTypeContext } from "../../hook/auth/userTypeFetcher"; | ||
import { useCheckCode } from "../../hook/api/useCheckCode"; | ||
|
@@ -38,6 +37,7 @@ export function LoginView() { | |
const loginCodeStore = useLoginCodeStore(); | ||
const { deployment } = useHealthcheck(); | ||
const [codeNotValid, setCodeNotValid] = useState(false); | ||
const [hasAutoSubmitted, setHasAutoSubmitted] = useState(false); | ||
const protocol = window.location.protocol; | ||
const host = window.location.host; | ||
const mtlsUrl = `${protocol}//mtls.${host}/app/admin/`; | ||
|
@@ -61,9 +61,13 @@ export function LoginView() { | |
}, | ||
}); | ||
|
||
// Destructure formik properties | ||
const { values, isValid, submitForm, setFieldValue } = formik; | ||
|
||
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
const upperCaseValue = e.target.value.toUpperCase(); | ||
void formik.setFieldValue("code", upperCaseValue); | ||
// Using void to intentionally ignore the Promise returned by setFieldValue, to suppress eslint | ||
void setFieldValue("code", upperCaseValue, false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the meaning of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ignoring the promise. No async operation there so I think there's nothig that could fail here |
||
}; | ||
|
||
const handleInputFocus = () => { | ||
|
@@ -77,7 +81,7 @@ export function LoginView() { | |
error, | ||
} = useCheckCode({ | ||
onSuccess: (data) => { | ||
loginCodeStore.setCode(formik.values.code); | ||
loginCodeStore.setCode(values.code); | ||
if (data.isAdminCodeValid) { | ||
loginCodeStore.setCodeType("admin"); | ||
setOtpVerified(true); | ||
|
@@ -97,6 +101,13 @@ export function LoginView() { | |
}, | ||
}); | ||
|
||
useEffect(() => { | ||
if (values.code && isValid && !isLoading && !hasAutoSubmitted) { | ||
setHasAutoSubmitted(true); | ||
void submitForm(); | ||
} | ||
}, [values.code, isValid, isLoading, hasAutoSubmitted, submitForm]); | ||
|
||
return ( | ||
<Layout showNavbar={false} showFooter={false} showPublicFooter={true}> | ||
<CardsContainer> | ||
|
@@ -138,7 +149,7 @@ export function LoginView() { | |
width: "full", | ||
}} | ||
type="submit" | ||
disabled={!formik.isValid || isLoading} | ||
disabled={!isValid || isLoading} | ||
styling={buttonStyle} | ||
> | ||
<div className="flex items-center justify-center w-full h-full"> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be using a helper function which uses a
switch case
for safer implementation.Although since the input value comes from the pre-defined options it doesn't matter that much.