-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TELEIWNOUME AURIO KAI PAIRNOUME 1 MILLION
- Loading branch information
Showing
1 changed file
with
118 additions
and
42 deletions.
There are no files selected for viewing
160 changes: 118 additions & 42 deletions
160
src/views/Home/components/ExistingUser/ExistingUser.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,127 @@ | ||
import { SetStateAction, useState } from "react" | ||
|
||
import React, { useState } from 'react'; | ||
import { | ||
Button, | ||
ChakraProvider, | ||
Container, | ||
FormControl, | ||
Input, | ||
Stack, | ||
Text, | ||
VStack, | ||
extendTheme, | ||
CSSReset, | ||
Box, | ||
Grid, | ||
} from '@chakra-ui/react'; | ||
Button, | ||
ChakraProvider, | ||
Container, | ||
FormControl, | ||
Input, | ||
Stack, | ||
Text, | ||
VStack, | ||
extendTheme, | ||
CSSReset, | ||
Box, | ||
Grid, | ||
Modal, | ||
ModalOverlay, | ||
ModalContent, | ||
ModalHeader, | ||
ModalBody, | ||
ModalFooter, | ||
ModalCloseButton, | ||
Alert, | ||
AlertIcon, | ||
} from '@chakra-ui/react'; | ||
import { IScUserInfo } from "@/utils/types/sc.interface"; | ||
|
||
// Define custom Chakra UI theme to control transitions | ||
|
||
const theme = extendTheme({ | ||
initialColorMode: 'light', | ||
initialColorMode: 'light', | ||
}); | ||
|
||
function ExistingUser(userInfo: IScUserInfo) { | ||
const [isWordsVisible, setWordsVisible] = useState(false); | ||
const [isPinModalOpen, setPinModalOpen] = useState(false); | ||
const [pin, setPin] = useState(''); | ||
const [showError, setShowError] = useState(false); | ||
const correctPin = '1234'; | ||
|
||
const toggleWordsVisibility = () => { | ||
if (pin === correctPin) { | ||
setWordsVisible(!isWordsVisible); | ||
setShowError(false); // Reset error state | ||
} else { | ||
setPinModalOpen(true); | ||
} | ||
}; | ||
|
||
const handlePinSubmit = () => { | ||
if (pin === correctPin) { | ||
setWordsVisible(true); | ||
setPinModalOpen(false); | ||
setShowError(false); // Reset error state | ||
} else { | ||
setShowError(true); | ||
setPin(''); | ||
setPinModalOpen(false); // Close the modal when PIN is incorrect | ||
} | ||
}; | ||
|
||
return ( | ||
<ChakraProvider theme={theme}> | ||
<CSSReset /> | ||
<Container maxW={'800px'}> | ||
<Text> | ||
<b>Username:</b> {userInfo.username} | ||
</Text> | ||
<Text> | ||
<b>Address:</b> {userInfo.address} | ||
</Text> | ||
<Button | ||
onClick={toggleWordsVisibility} | ||
size="sm" | ||
colorScheme="teal" | ||
> | ||
Words | ||
</Button> | ||
|
||
{isWordsVisible && ( | ||
<Grid templateColumns="repeat(6, 1fr)" gap={6}> | ||
{userInfo.secretWords.map((word, index) => ( | ||
<Text key={index} as="span" border="1px solid black" padding="1" m={1}> | ||
{word} | ||
</Text> | ||
))} | ||
</Grid> | ||
)} | ||
<Modal isOpen={isPinModalOpen} onClose={() => setPinModalOpen(false)} isCentered> | ||
<ModalOverlay /> | ||
<ModalContent | ||
bg="transparent" // Set background to transparent | ||
w="30%" // Set the width to 30% of the screen | ||
borderWidth="2px" // Add border for visibility | ||
borderColor="teal.500" // Customize the border color | ||
borderRadius="15px" // Add border radius | ||
> | ||
<ModalHeader color="white">Enter PIN</ModalHeader> | ||
<ModalCloseButton /> | ||
<ModalBody> | ||
<FormControl> | ||
<Input | ||
type="password" | ||
placeholder="Enter 4-digit PIN" | ||
value={pin} | ||
onChange={(e) => setPin(e.target.value)} | ||
/> | ||
</FormControl> | ||
</ModalBody> | ||
<ModalFooter> | ||
<Button colorScheme="teal" onClick={handlePinSubmit}> | ||
Submit | ||
</Button> | ||
</ModalFooter> | ||
</ModalContent> | ||
</Modal> | ||
|
||
|
||
return ( | ||
<ChakraProvider theme={theme}> | ||
<CSSReset /> | ||
<Container maxW={'800px'}> | ||
<Text> | ||
<b>Username:</b> {userInfo.username} | ||
</Text> | ||
<Text> | ||
<b>Address:</b> {userInfo.address} | ||
</Text> | ||
<Text> | ||
<b>Words:</b> | ||
</Text> | ||
<Grid templateColumns="repeat(6, 1fr)" gap={6}> | ||
{userInfo.secretWords.map((word, index) => ( | ||
<Text key={index} as="span" border="1px solid black" padding="1" m={1}> | ||
{word} | ||
</Text> | ||
))} | ||
</Grid> | ||
</Container> | ||
</ChakraProvider> | ||
); | ||
{showError && ( | ||
<Alert status="error"> | ||
<AlertIcon /> | ||
Incorrect PIN. Please try again. | ||
</Alert> | ||
)} | ||
</Container> | ||
</ChakraProvider> | ||
); | ||
} | ||
|
||
export default ExistingUser; | ||
export default ExistingUser; |