From ea8dff4e3bef1d450a4870bec08d5b3173f7d720 Mon Sep 17 00:00:00 2001 From: Kostas Tzoumpas Date: Thu, 5 Oct 2023 12:21:53 +0300 Subject: [PATCH] form --- .../{CreateWallet => Form}/CreateWallet.tsx | 0 src/pages/Form/Form.tsx | 142 ++++++++++++++++++ src/pages/index.tsx | 4 +- 3 files changed, 144 insertions(+), 2 deletions(-) rename src/pages/{CreateWallet => Form}/CreateWallet.tsx (100%) create mode 100644 src/pages/Form/Form.tsx diff --git a/src/pages/CreateWallet/CreateWallet.tsx b/src/pages/Form/CreateWallet.tsx similarity index 100% rename from src/pages/CreateWallet/CreateWallet.tsx rename to src/pages/Form/CreateWallet.tsx diff --git a/src/pages/Form/Form.tsx b/src/pages/Form/Form.tsx new file mode 100644 index 0000000..127309d --- /dev/null +++ b/src/pages/Form/Form.tsx @@ -0,0 +1,142 @@ +import { SetStateAction, useState } from "react" + +import { + Button, + ChakraProvider, + Container, + FormControl, + Input, + Stack, + Text, + VStack, + extendTheme, + CSSReset, + Box, + } from '@chakra-ui/react'; + +// Define custom Chakra UI theme to control transitions +const theme = extendTheme({ + initialColorMode: 'light', +}); + +interface Step1Props { + formData: { + username?: string; + }; + onNext: (data: { username: string }) => void; +} + +function Step1({ formData, onNext }: Step1Props) { + const [username, setUsername] = useState(formData.username || ''); + + const handleNext = () => { + onNext({ username }); + }; + + return ( + + Step 1: Enter Username + + setUsername(e.target.value)} + /> + + + + ); +} + +interface Step2Props { + formData: { + pin?: string; + }; + onPrevious: () => void; + onNext: (data: { pin: string }) => void; +} + +function Step2({ formData, onPrevious, onNext }: Step2Props) { + const [pin, setPin] = useState(formData.pin || ''); + + const handlePrevious = () => { + onPrevious(); + }; + + const handleNext = () => { + onNext({ pin }); + }; + + return ( + + Step 2: Enter PIN + + setPin(e.target.value)} + /> + + + + + + + ); +} + +function Form() { + const [step, setStep] = useState(1); + const [formData, setFormData] = useState({}); + + const handleNext = (data: SetStateAction<{}>) => { + setFormData({ ...formData, ...data }); + setStep(step + 1); + }; + + const handlePrevious = () => { + setStep(step - 1); + }; + + const handleReset = () => { + setStep(1); + setFormData({}); + } + + return ( + + + + {step === 1 && } + {step === 2 && ( + + )} + {step > 2 && ( + <> + Review and Submit +
{JSON.stringify(formData, null, 2)}
+ {/* Add a submit button here */} +
+ + + + + )} +
+
+ ); +} + +export default Form; \ No newline at end of file diff --git a/src/pages/index.tsx b/src/pages/index.tsx index 55c067c..e290062 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -1,6 +1,6 @@ import { useSession, signIn, signOut } from "next-auth/react" import { Button, Box } from "@chakra-ui/react"; -import CreateWallet from "./CreateWallet/CreateWallet"; +import Form from "./Form/Form"; export default function Home() { @@ -21,7 +21,7 @@ export default function Home() { > Sign Out - +
) }