mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-06 13:27:22 +00:00
Merge pull request #711 from afrieirham/form-ux-enhancement
fix: enable users to press `Enter` in forms
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { useState } from "react";
|
import { FormEvent, useState } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
@@ -31,7 +31,8 @@ export default function InitialLoginStep({
|
|||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const [loginError, setLoginError] = useState(false);
|
const [loginError, setLoginError] = useState(false);
|
||||||
|
|
||||||
const handleLogin = async () => {
|
const handleLogin = async (e: FormEvent<HTMLFormElement>) => {
|
||||||
|
e.preventDefault()
|
||||||
try {
|
try {
|
||||||
if (!email || !password) {
|
if (!email || !password) {
|
||||||
return;
|
return;
|
||||||
@@ -98,7 +99,7 @@ export default function InitialLoginStep({
|
|||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return <div className='flex flex-col mx-auto w-full justify-center items-center'>
|
return <form onSubmit={handleLogin} className='flex flex-col mx-auto w-full justify-center items-center'>
|
||||||
<h1 className='text-xl font-medium text-transparent bg-clip-text bg-gradient-to-b from-white to-bunker-200 text-center mb-8' >Login to Infisical</h1>
|
<h1 className='text-xl font-medium text-transparent bg-clip-text bg-gradient-to-b from-white to-bunker-200 text-center mb-8' >Login to Infisical</h1>
|
||||||
{/* <div className='lg:w-1/6 w-1/4 min-w-[20rem] rounded-md'>
|
{/* <div className='lg:w-1/6 w-1/4 min-w-[20rem] rounded-md'>
|
||||||
<Button
|
<Button
|
||||||
@@ -143,7 +144,7 @@ export default function InitialLoginStep({
|
|||||||
{!isLoading && loginError && <Error text={t("login.error-login") ?? ""} />}
|
{!isLoading && loginError && <Error text={t("login.error-login") ?? ""} />}
|
||||||
<div className='lg:w-1/6 w-1/4 min-w-[21.2rem] md:min-w-[20.1rem] text-center rounded-md mt-4'>
|
<div className='lg:w-1/6 w-1/4 min-w-[21.2rem] md:min-w-[20.1rem] text-center rounded-md mt-4'>
|
||||||
<Button
|
<Button
|
||||||
onClick={async () => handleLogin()}
|
type="submit"
|
||||||
size="sm"
|
size="sm"
|
||||||
isFullWidth
|
isFullWidth
|
||||||
className='h-12'
|
className='h-12'
|
||||||
@@ -180,5 +181,5 @@ export default function InitialLoginStep({
|
|||||||
<span className='hover:underline hover:underline-offset-4 hover:decoration-primary-700 hover:text-bunker-200 duration-200 cursor-pointer'>Recover your account</span>
|
<span className='hover:underline hover:underline-offset-4 hover:decoration-primary-700 hover:text-bunker-200 duration-200 cursor-pointer'>Recover your account</span>
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</form>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -114,6 +114,7 @@ export default function CodeInputStep({
|
|||||||
<div className="flex flex-col items-center justify-center lg:w-[19%] w-1/4 min-w-[20rem] mt-2 max-w-xs md:max-w-md mx-auto text-sm text-center md:text-left">
|
<div className="flex flex-col items-center justify-center lg:w-[19%] w-1/4 min-w-[20rem] mt-2 max-w-xs md:max-w-md mx-auto text-sm text-center md:text-left">
|
||||||
<div className="text-l py-1 text-lg w-full">
|
<div className="text-l py-1 text-lg w-full">
|
||||||
<Button
|
<Button
|
||||||
|
type="submit"
|
||||||
onClick={incrementStep}
|
onClick={incrementStep}
|
||||||
size="sm"
|
size="sm"
|
||||||
isFullWidth
|
isFullWidth
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ export default function EnterEmailStep({
|
|||||||
<div className="flex flex-col items-center justify-center lg:w-1/6 w-1/4 min-w-[20rem] mt-2 max-w-xs md:max-w-md mx-auto text-sm text-center md:text-left">
|
<div className="flex flex-col items-center justify-center lg:w-1/6 w-1/4 min-w-[20rem] mt-2 max-w-xs md:max-w-md mx-auto text-sm text-center md:text-left">
|
||||||
<div className="text-l py-1 text-lg w-full">
|
<div className="text-l py-1 text-lg w-full">
|
||||||
<Button
|
<Button
|
||||||
|
type="submit"
|
||||||
onClick={emailCheck}
|
onClick={emailCheck}
|
||||||
size="sm"
|
size="sm"
|
||||||
isFullWidth
|
isFullWidth
|
||||||
|
|||||||
@@ -248,7 +248,6 @@ export default function UserInfoStep({
|
|||||||
placeholder=""
|
placeholder=""
|
||||||
onChange={(e) => setAttributionSource(e.target.value)}
|
onChange={(e) => setAttributionSource(e.target.value)}
|
||||||
value={attributionSource}
|
value={attributionSource}
|
||||||
isRequired
|
|
||||||
className="h-12"
|
className="h-12"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -301,6 +300,7 @@ export default function UserInfoStep({
|
|||||||
<div className="flex flex-col items-center justify-center lg:w-[19%] w-1/4 min-w-[20rem] mt-2 max-w-xs md:max-w-md mx-auto text-sm text-center md:text-left">
|
<div className="flex flex-col items-center justify-center lg:w-[19%] w-1/4 min-w-[20rem] mt-2 max-w-xs md:max-w-md mx-auto text-sm text-center md:text-left">
|
||||||
<div className="text-l py-1 text-lg w-full">
|
<div className="text-l py-1 text-lg w-full">
|
||||||
<Button
|
<Button
|
||||||
|
type="submit"
|
||||||
onClick={signupErrorCheck}
|
onClick={signupErrorCheck}
|
||||||
size="sm"
|
size="sm"
|
||||||
isFullWidth
|
isFullWidth
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import crypto from "crypto";
|
import crypto from "crypto";
|
||||||
|
|
||||||
import { useState } from "react";
|
import { FormEvent, useState } from "react";
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
import { faCheck, faX } from "@fortawesome/free-solid-svg-icons";
|
import { faCheck, faX } from "@fortawesome/free-solid-svg-icons";
|
||||||
@@ -24,6 +24,7 @@ const client = new jsrp.client();
|
|||||||
export default function PasswordReset() {
|
export default function PasswordReset() {
|
||||||
const [verificationToken, setVerificationToken] = useState("");
|
const [verificationToken, setVerificationToken] = useState("");
|
||||||
const [step, setStep] = useState(1);
|
const [step, setStep] = useState(1);
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
const [backupKey, setBackupKey] = useState("");
|
const [backupKey, setBackupKey] = useState("");
|
||||||
const [privateKey, setPrivateKey] = useState("");
|
const [privateKey, setPrivateKey] = useState("");
|
||||||
const [newPassword, setNewPassword] = useState("");
|
const [newPassword, setNewPassword] = useState("");
|
||||||
@@ -38,7 +39,8 @@ export default function PasswordReset() {
|
|||||||
const email = (parsedUrl.to as string)?.replace(" ", "+").trim();
|
const email = (parsedUrl.to as string)?.replace(" ", "+").trim();
|
||||||
|
|
||||||
// Unencrypt the private key with a backup key
|
// Unencrypt the private key with a backup key
|
||||||
const getEncryptedKeyHandler = async () => {
|
const getEncryptedKeyHandler = async (e: FormEvent<HTMLFormElement>) => {
|
||||||
|
e.preventDefault();
|
||||||
try {
|
try {
|
||||||
const result = await getBackupEncryptedPrivateKey({ verificationToken });
|
const result = await getBackupEncryptedPrivateKey({ verificationToken });
|
||||||
|
|
||||||
@@ -57,7 +59,8 @@ export default function PasswordReset() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// If everything is correct, reset the password
|
// If everything is correct, reset the password
|
||||||
const resetPasswordHandler = async () => {
|
const resetPasswordHandler = async (e: FormEvent<HTMLFormElement>) => {
|
||||||
|
e.preventDefault();
|
||||||
const errorCheck = passwordCheck({
|
const errorCheck = passwordCheck({
|
||||||
password: newPassword,
|
password: newPassword,
|
||||||
setPasswordErrorLength,
|
setPasswordErrorLength,
|
||||||
@@ -125,6 +128,7 @@ export default function PasswordReset() {
|
|||||||
if (response?.status === 200) {
|
if (response?.status === 200) {
|
||||||
router.push("/login");
|
router.push("/login");
|
||||||
}
|
}
|
||||||
|
setLoading(false)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -162,7 +166,7 @@ export default function PasswordReset() {
|
|||||||
|
|
||||||
// Input backup key
|
// Input backup key
|
||||||
const stepInputBackupKey = (
|
const stepInputBackupKey = (
|
||||||
<div className="my-32 mx-1 flex w-full max-w-xs flex-col items-center rounded-xl bg-bunker px-4 pt-6 pb-3 drop-shadow-xl md:max-w-lg md:px-6">
|
<form onSubmit={getEncryptedKeyHandler} className="my-32 mx-1 flex w-full max-w-xs flex-col items-center rounded-xl bg-bunker px-4 pt-6 pb-3 drop-shadow-xl md:max-w-lg md:px-6">
|
||||||
<p className="mx-auto mb-4 flex w-max justify-center text-2xl font-semibold text-bunker-100 md:text-3xl">
|
<p className="mx-auto mb-4 flex w-max justify-center text-2xl font-semibold text-bunker-100 md:text-3xl">
|
||||||
Enter your backup key
|
Enter your backup key
|
||||||
</p>
|
</p>
|
||||||
@@ -186,18 +190,19 @@ export default function PasswordReset() {
|
|||||||
<div className="mx-auto mt-4 flex max-h-20 w-full max-w-md flex-col items-center justify-center text-sm md:p-2">
|
<div className="mx-auto mt-4 flex max-h-20 w-full max-w-md flex-col items-center justify-center text-sm md:p-2">
|
||||||
<div className="text-l m-8 mt-6 px-8 py-3 text-lg">
|
<div className="text-l m-8 mt-6 px-8 py-3 text-lg">
|
||||||
<Button
|
<Button
|
||||||
|
type="submit"
|
||||||
text="Submit Backup Key"
|
text="Submit Backup Key"
|
||||||
onButtonPressed={() => getEncryptedKeyHandler()}
|
onButtonPressed={() => {}}
|
||||||
size="lg"
|
size="lg"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</form>
|
||||||
);
|
);
|
||||||
|
|
||||||
// Enter new password
|
// Enter new password
|
||||||
const stepEnterNewPassword = (
|
const stepEnterNewPassword = (
|
||||||
<div className="my-32 mx-1 flex w-full max-w-xs flex-col items-center rounded-xl bg-bunker px-4 pt-6 pb-3 drop-shadow-xl md:max-w-lg md:px-6">
|
<form onSubmit={resetPasswordHandler} className="my-32 mx-1 flex w-full max-w-xs flex-col items-center rounded-xl bg-bunker px-4 pt-6 pb-3 drop-shadow-xl md:max-w-lg md:px-6">
|
||||||
<p className="mx-auto flex w-max justify-center text-2xl font-semibold text-bunker-100 md:text-3xl">
|
<p className="mx-auto flex w-max justify-center text-2xl font-semibold text-bunker-100 md:text-3xl">
|
||||||
Enter new password
|
Enter new password
|
||||||
</p>
|
</p>
|
||||||
@@ -269,13 +274,15 @@ export default function PasswordReset() {
|
|||||||
<div className="mx-auto mt-4 flex max-h-20 w-full max-w-md flex-col items-center justify-center text-sm md:p-2">
|
<div className="mx-auto mt-4 flex max-h-20 w-full max-w-md flex-col items-center justify-center text-sm md:p-2">
|
||||||
<div className="text-l m-8 mt-6 px-8 py-3 text-lg">
|
<div className="text-l m-8 mt-6 px-8 py-3 text-lg">
|
||||||
<Button
|
<Button
|
||||||
|
type="submit"
|
||||||
text="Submit New Password"
|
text="Submit New Password"
|
||||||
onButtonPressed={() => resetPasswordHandler()}
|
onButtonPressed={() => setLoading(true)}
|
||||||
size="lg"
|
size="lg"
|
||||||
|
loading={loading}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</form>
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useState } from "react";
|
import { FormEvent, useState } from "react";
|
||||||
import Head from "next/head";
|
import Head from "next/head";
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
@@ -12,6 +12,7 @@ import { useFetchServerStatus } from "@app/hooks/api/serverDetails";
|
|||||||
import SendEmailOnPasswordReset from "./api/auth/SendEmailOnPasswordReset";
|
import SendEmailOnPasswordReset from "./api/auth/SendEmailOnPasswordReset";
|
||||||
|
|
||||||
export default function VerifyEmail() {
|
export default function VerifyEmail() {
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
const [email, setEmail] = useState("");
|
const [email, setEmail] = useState("");
|
||||||
const [step, setStep] = useState(1);
|
const [step, setStep] = useState(1);
|
||||||
const { data: serverDetails } = useFetchServerStatus();
|
const { data: serverDetails } = useFetchServerStatus();
|
||||||
@@ -27,6 +28,18 @@ export default function VerifyEmail() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const onSubmit = (e: FormEvent<HTMLFormElement>) => {
|
||||||
|
e.preventDefault();
|
||||||
|
setLoading(true);
|
||||||
|
|
||||||
|
if (serverDetails?.emailConfigured) {
|
||||||
|
sendVerificationEmail();
|
||||||
|
} else {
|
||||||
|
handlePopUpOpen("setUpEmail");
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex h-screen flex-col justify-start bg-bunker-800 px-6">
|
<div className="flex h-screen flex-col justify-start bg-bunker-800 px-6">
|
||||||
<Head>
|
<Head>
|
||||||
@@ -45,7 +58,7 @@ export default function VerifyEmail() {
|
|||||||
</div>
|
</div>
|
||||||
</Link>
|
</Link>
|
||||||
{step === 1 && (
|
{step === 1 && (
|
||||||
<div className="h-7/12 mx-auto w-full max-w-md rounded-xl bg-bunker py-4 px-6 pt-8 drop-shadow-xl">
|
<form onSubmit={onSubmit} className="h-7/12 mx-auto w-full max-w-md rounded-xl bg-bunker px-6 py-4 pt-8 drop-shadow-xl">
|
||||||
<p className="mx-auto mb-6 flex w-max justify-center text-2xl font-semibold text-bunker-100 md:text-3xl">
|
<p className="mx-auto mb-6 flex w-max justify-center text-2xl font-semibold text-bunker-100 md:text-3xl">
|
||||||
Forgot your password?
|
Forgot your password?
|
||||||
</p>
|
</p>
|
||||||
@@ -67,20 +80,10 @@ export default function VerifyEmail() {
|
|||||||
</div>
|
</div>
|
||||||
<div className="mx-auto mt-4 flex max-h-20 w-full max-w-md flex-col items-center justify-center text-sm md:p-2">
|
<div className="mx-auto mt-4 flex max-h-20 w-full max-w-md flex-col items-center justify-center text-sm md:p-2">
|
||||||
<div className="text-l m-8 mt-6 px-8 py-3 text-lg">
|
<div className="text-l m-8 mt-6 px-8 py-3 text-lg">
|
||||||
<Button
|
<Button type="submit" text="Continue" size="lg" onButtonPressed={() => {}} loading={loading} />
|
||||||
text="Continue"
|
|
||||||
onButtonPressed={() => {
|
|
||||||
if (serverDetails?.emailConfigured) {
|
|
||||||
sendVerificationEmail();
|
|
||||||
} else {
|
|
||||||
handlePopUpOpen("setUpEmail");
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
size="lg"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</form>
|
||||||
)}
|
)}
|
||||||
{step === 2 && (
|
{step === 2 && (
|
||||||
<div className="h-7/12 mx-auto w-full max-w-md rounded-xl bg-bunker py-4 px-6 pt-8 drop-shadow-xl">
|
<div className="h-7/12 mx-auto w-full max-w-md rounded-xl bg-bunker py-4 px-6 pt-8 drop-shadow-xl">
|
||||||
|
|||||||
Reference in New Issue
Block a user