MCPcopy Create free account
hub / github.com/code100x/cms / Signin

Function Signin

src/components/Signin.tsx:21–324  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

19];
20
21const Signin = () => {
22 const [isPasswordVisible, setIsPasswordVisible] = useState(false);
23 const [checkingPassword, setCheckingPassword] = useState(false);
24 const [requiredError, setRequiredError] = useState({
25 emailReq: false,
26 passReq: false,
27 });
28 const [suggestedDomains, setSuggestedDomains] =
29 useState<string[]>(emailDomains);
30 const [focusedIndex, setFocusedIndex] = useState(-1);
31 const passwordRef = useRef<HTMLInputElement>(null);
32 const suggestionRefs = useRef<HTMLLIElement[]>([]);
33 const dropdownRef = useRef<HTMLUListElement>(null);
34
35 function togglePasswordVisibility() {
36 setIsPasswordVisible((prevState: any) => !prevState);
37 }
38 const router = useRouter();
39 const email = useRef('');
40 const password = useRef('');
41
42 const handleEmailChange = (e: React.ChangeEvent<HTMLInputElement>) => {
43 const value = e.target.value;
44 email.current = value;
45
46 setFocusedIndex(0);
47 setRequiredError((prevState) => ({
48 ...prevState,
49 emailReq: false,
50 }));
51
52 // Check if the input is a phone number
53 const phoneNumberRegex = /^[0-9]{10}$/;
54 if (phoneNumberRegex.test(value)) {
55 setSuggestedDomains([]); // Clear suggestions for phone numbers
56 return;
57 }
58
59 if (!value.includes('@')) {
60 setSuggestedDomains(emailDomains);
61 return;
62 }
63
64 const [, currentDomain] = value.split('@');
65
66 // Clear suggestions if domain doesn't match
67 if (
68 !currentDomain ||
69 !emailDomains.some((domain) => domain.startsWith(currentDomain))
70 ) {
71 setSuggestedDomains([]); // Hide suggestions for mismatched domains
72 return;
73 }
74
75 // Check for exact matches and filter for partial matches
76 const exactMatch = emailDomains.find((domain) => domain === currentDomain);
77 if (exactMatch) {
78 setSuggestedDomains([]);

Callers

nothing calls this directly

Calls 2

handleSuggestionClickFunction · 0.85
handleSubmitFunction · 0.70

Tested by

no test coverage detected