Skip to content

Commit d1da703

Browse files
committed
CCSD-1077 : updated the login page to handle email based login (#3243)
* CCSD-1077 : updated the login page to handle email based login * Updated the logic for mobile number
1 parent ef248df commit d1da703

File tree

2 files changed

+60
-11
lines changed

2 files changed

+60
-11
lines changed

micro-ui/web/micro-ui-internals/example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"@egovernments/digit-ui-module-workbench": "1.0.21",
1414
"@egovernments/digit-ui-module-pgr": "1.8.12",
1515
"@egovernments/digit-ui-module-dss": "1.8.12",
16-
"@egovernments/digit-ui-module-core": "1.8.32",
16+
"@egovernments/digit-ui-module-core": "1.8.33",
1717
"@egovernments/digit-ui-module-common": "1.8.10",
1818
"@egovernments/digit-ui-module-hrms": "1.8.11",
1919
"@egovernments/digit-ui-module-utilities": "1.0.15",

micro-ui/web/micro-ui-internals/packages/modules/core/src/pages/citizen/Login/SelectMobileNumber.js

Lines changed: 59 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,66 @@
1-
import { FormStep } from "@egovernments/digit-ui-components";
2-
import React from "react";
1+
import { ToggleSwitch, InputCard, TextBlock, FieldV1 } from "@egovernments/digit-ui-components";
2+
import React, { useMemo, useState } from "react";
33

44
const SelectMobileNumber = ({ t, onSelect, showRegisterLink, mobileNumber, onMobileChange, config, canSubmit }) => {
5+
const [isEmail, setIsEmail] = useState(false);
6+
const [email, setEmail] = useState("");
7+
8+
const EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
9+
10+
const isEmailValid = useMemo(() => EMAIL_REGEX.test(email), [email]);
11+
const isDisabled = useMemo(() => {
12+
return isEmail ? !(isEmailValid && canSubmit) : !(isMobileValid && canSubmit);
13+
}, [isEmail, isEmailValid, isMobileValid, canSubmit]);
14+
15+
const handleSubmit = () => {
16+
if (isEmail) {
17+
onSelect({ userName: email });
18+
} else {
19+
onSelect({ mobileNumber });
20+
}
21+
};
22+
23+
const core_mobile_config = window?.globalConfigs?.getConfig("CORE_MOBILE_CONFIGS") || {};
24+
const isMobileValid = useMemo(() => mobileNumber && mobileNumber.length === core_mobile_config?.mobileNumberLength, [mobileNumber]);
25+
526
return (
6-
<FormStep
7-
isDisabled={!(mobileNumber.length === 10 && canSubmit)}
8-
onSelect={onSelect}
9-
config={config}
27+
<InputCard
1028
t={t}
11-
componentInFront="+91"
12-
onChange={onMobileChange}
13-
value={mobileNumber}
14-
></FormStep>
29+
texts={config?.texts}
30+
submit
31+
onNext={handleSubmit}
32+
isDisable={isDisabled}
33+
>
34+
<div>
35+
<FieldV1
36+
withoutLabel={true}
37+
charCount={true}
38+
onChange={isEmail ? (e) => setEmail(e.target.value) : onMobileChange}
39+
placeholder={isEmail ? t("ENTER_EMAIL_PLACEHOLDER") : t("ENTER_MOBILE_PLACEHOLDER")}
40+
populators={{
41+
name : isEmail ? "userName" : "mobileNumber",
42+
prefix: isEmail ? "" : core_mobile_config?.mobilePrefix
43+
}}
44+
props={{
45+
fieldStyle: { width: "100%" }
46+
}}
47+
required
48+
type="text"
49+
value={isEmail ? email : mobileNumber}
50+
/>
51+
</div>
52+
53+
<div style={{ display: "flex", alignItems: "center", gap: "1rem", marginBottom: "1.5rem", marginTop:"-24px" }}>
54+
<TextBlock body={t("CS_MOBILE_OR_EMAIL")}></TextBlock>
55+
<ToggleSwitch
56+
name="loginWithEmail"
57+
style={{ marginTop: "-1rem" }}
58+
value={isEmail}
59+
onChange={() => setIsEmail(!isEmail)}
60+
label={isEmail ? t("CS_USE_MOBILE_INSTEAD") : t("CS_LOGIN_REGISTER_WITH_EMAIL")}
61+
/>
62+
</div>
63+
</InputCard>
1564
);
1665
};
1766

0 commit comments

Comments
 (0)