Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

Firming up the sign in forms so they "submit" and use the right input type.

Matt Roberts7bb5a9351cc8
diff --git a/public/components/common/SignInControl.tsx b/public/components/common/SignInControl.tsx
index b0b551ad8..1be99bbc0 100644
--- a/public/components/common/SignInControl.tsx
+++ b/public/components/common/SignInControl.tsx
@@ -125,24 +125,36 @@ export const SignInControl: React.FunctionComponent<SignInControlProps> = (props
const providersLen = fider.settings.oauth.length
+ const handleFormSubmit = async (e: React.FormEvent) => {
+ e.preventDefault()
+ // Form submission handler that routes to the correct function based on step
+ if (emailSignInStep === EmailSigninStep.EnterEmail) {
+ await signIn()
+ } else if (emailSignInStep === EmailSigninStep.EnterName) {
+ await submitNewUser()
+ } else if (emailSignInStep === EmailSigninStep.EnterCode) {
+ await verifyCode()
+ }
+ }
+
const renderSigninEmailButton = () => {
if (emailSignInStep == EmailSigninStep.EnterEmail) {
return (
- <Button className="w-full justify-center" type="submit" variant="primary" onClick={signIn}>
+ <Button className="w-full justify-center" type="submit" variant="primary">
<Trans id="signin.message.email">Continue with Email</Trans>
</Button>
)
}
if (emailSignInStep == EmailSigninStep.EnterName) {
return (
- <Button className="w-full justify-center" type="submit" variant="primary" onClick={submitNewUser}>
+ <Button className="w-full justify-center" type="submit" variant="primary">
<Trans id="action.signup">Sign up</Trans>
</Button>
)
}
if (emailSignInStep == EmailSigninStep.EnterCode) {
return (
- <Button className="w-full justify-center" type="submit" variant="primary" disabled={code.length !== 6} onClick={verifyCode}>
+ <Button className="w-full justify-center" type="submit" variant="primary" disabled={code.length !== 6}>
<Trans id="action.submit">Submit</Trans>
</Button>
)
@@ -176,7 +188,7 @@ export const SignInControl: React.FunctionComponent<SignInControlProps> = (props
{props.useEmail &&
(showEmailForm ? (
<div className="pt-3">
- <Form error={error}>
+ <Form error={error} autoComplete={emailSignInStep === EmailSigninStep.EnterCode ? "on" : "off"} onSubmit={handleFormSubmit}>
{(emailSignInStep == EmailSigninStep.EnterEmail || emailSignInStep == EmailSigninStep.EnterName) && renderEmailField()}
{emailSignInStep == EmailSigninStep.EnterName && renderNameField()}
@@ -225,6 +237,7 @@ export const SignInControl: React.FunctionComponent<SignInControlProps> = (props
value={email}
disabled={emailSignInStep == EmailSigninStep.EnterName}
autoFocus={!device.isTouch()}
+ autoComplete="email"
onChange={setEmail}
placeholder={i18n._({ id: "signin.email.placeholder", message: "Email address" })}
/>
@@ -255,17 +268,17 @@ export const SignInControl: React.FunctionComponent<SignInControlProps> = (props
<Trans id="signin.code.edit">Edit</Trans>
</a>
</p>
- <Form error={error}>
- <Input
- className="text-left"
- field="code"
- value={code}
- autoFocus={!device.isTouch()}
- onChange={setCode}
- placeholder={i18n._({ id: "signin.code.placeholder", message: "Type in the code here" })}
- maxLength={6}
- />
- </Form>
+ <Input
+ className="text-left"
+ field="code"
+ value={code}
+ autoFocus={!device.isTouch()}
+ autoComplete="one-time-code"
+ inputMode="numeric"
+ onChange={setCode}
+ placeholder={i18n._({ id: "signin.code.placeholder", message: "Type in the code here" })}
+ maxLength={6}
+ />
{resendMessage && <p className="text-green-700 mt-2">{resendMessage}</p>}
<p className="text-center mt-2 text-muted text-left">
<a
diff --git a/public/components/common/form/Form.tsx b/public/components/common/form/Form.tsx
index 1096b5cdc..9a532207c 100644
--- a/public/components/common/form/Form.tsx
+++ b/public/components/common/form/Form.tsx
@@ -13,6 +13,8 @@ interface FormProps {
children?: React.ReactNode
className?: string
error?: Failure
+ autoComplete?: string
+ onSubmit?: (e: React.FormEvent) => void
}
export const ValidationContext = React.createContext<ValidationContext>({
@@ -45,8 +47,15 @@ export const Form: React.FunctionComponent<FormProps> = (props) => {
}
}
+ const handleSubmit = (e: React.FormEvent) => {
+ if (props.onSubmit) {
+ e.preventDefault()
+ props.onSubmit(e)
+ }
+ }
+
return (
- <form autoComplete="off" className={className}>
+ <form autoComplete={props.autoComplete || "off"} className={className} onSubmit={handleSubmit}>
<DisplayError error={formError} />
<ValidationContext.Provider value={{ error: formError, clearError }}>{props.children}</ValidationContext.Provider>
</form>
diff --git a/public/components/common/form/Input.tsx b/public/components/common/form/Input.tsx
index eb77ecb8b..516bca7bd 100644
--- a/public/components/common/form/Input.tsx
+++ b/public/components/common/form/Input.tsx
@@ -22,6 +22,7 @@ interface InputProps {
disabled?: boolean
suffix?: string | JSX.Element
placeholder?: string
+ inputMode?: "text" | "numeric" | "decimal" | "tel" | "search" | "email" | "url"
onIconClick?: () => void
onFocus?: () => void
inputRef?: React.MutableRefObject<any>
@@ -80,6 +81,7 @@ export const Input: React.FunctionComponent<InputProps> = (props) => {
id={`input-${props.field}`}
type="text"
autoComplete={props.autoComplete}
+ inputMode={props.inputMode}
tabIndex={props.noTabFocus ? -1 : undefined}
ref={props.inputRef}
autoFocus={props.autoFocus}