change style & add space & validation number in register page
This commit is contained in:
@@ -1,16 +1,21 @@
|
|||||||
import { TextField } from "@mui/material";
|
import { TextField } from "@mui/material";
|
||||||
import { styleTextSelectRight } from "@/mui";
|
import { styleTextSelectRight } from "@/mui";
|
||||||
|
|
||||||
function Field({ title, type, dir, value, updateState }) {
|
function Field({ title, error, inputProps, type, dir, value, updateState }) {
|
||||||
return (
|
return (
|
||||||
<TextField
|
<TextField
|
||||||
label={title}
|
label={title}
|
||||||
|
error={error}
|
||||||
dir={dir || "rtl"}
|
dir={dir || "rtl"}
|
||||||
type={type || "text"}
|
type={type || "text"}
|
||||||
value={value}
|
value={value}
|
||||||
onChange={(e) => updateState(e.target.value)}
|
onChange={(e) => updateState(e.target.value)}
|
||||||
className="!w-full !mx-auto !bg-[#FFF]"
|
className="!w-full !mx-auto !bg-[#FFF]"
|
||||||
|
InputProps={inputProps}
|
||||||
sx={{
|
sx={{
|
||||||
|
'.MuiOutlinedInput-notchedOutline.muirtl-1d3z3hw-MuiOutlinedInput-notchedOutline': {
|
||||||
|
border: error && '1px solid red !important'
|
||||||
|
},
|
||||||
...styleTextSelectRight,
|
...styleTextSelectRight,
|
||||||
// Hide Icon Number
|
// Hide Icon Number
|
||||||
"& input::-webkit-outer-spin-button, & input::-webkit-inner-spin-button":
|
"& input::-webkit-outer-spin-button, & input::-webkit-inner-spin-button":
|
||||||
@@ -20,8 +25,7 @@ function Field({ title, type, dir, value, updateState }) {
|
|||||||
"& input[type=number]": {
|
"& input[type=number]": {
|
||||||
MozAppearance: "textfield",
|
MozAppearance: "textfield",
|
||||||
},
|
},
|
||||||
// "& .MuiFormLabel-root": { top: "-7px !important" },
|
"& .MuiInputBase-input": { padding: "12.5px 0" },
|
||||||
"& .MuiInputBase-input": { padding: "12.5px 14px" },
|
|
||||||
"& .MuiInputBase-root": { borderRadius: "6px !important" },
|
"& .MuiInputBase-root": { borderRadius: "6px !important" },
|
||||||
"& .MuiOutlinedInput-notchedOutline": {
|
"& .MuiOutlinedInput-notchedOutline": {
|
||||||
border: "1px solid #E9ECEF !important",
|
border: "1px solid #E9ECEF !important",
|
||||||
|
|||||||
@@ -1,12 +1,16 @@
|
|||||||
import Field from "@/app/component/element/Field";
|
import Field from "@/app/component/element/Field";
|
||||||
import { Button } from "@mui/material";
|
import { formatPhoneNumber, validatePhoneNumber } from "@/helper";
|
||||||
|
import { Button, InputAdornment } from "@mui/material";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
|
|
||||||
function LogInPage({ setIsSendMsg, setStep }) {
|
function LogInPage({ setIsSendMsg, setStep }) {
|
||||||
const [num, setNum] = useState("09");
|
const [num, setNum] = useState("");
|
||||||
const updateNum = (value) => {
|
const [error, setError] = useState(false);
|
||||||
setNum(value === "0" || !value ? "09" : value);
|
|
||||||
|
const handleChange = (val) => {
|
||||||
|
const formatted = formatPhoneNumber(val);
|
||||||
|
setNum(formatted);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -20,19 +24,43 @@ function LogInPage({ setIsSendMsg, setStep }) {
|
|||||||
<p className="text-[#616161] text-[14px] mt-[40px] sm:mt-[43px] md:mt-[46px] lg:mt-[48px] font-normal">
|
<p className="text-[#616161] text-[14px] mt-[40px] sm:mt-[43px] md:mt-[46px] lg:mt-[48px] font-normal">
|
||||||
شماره همراه خود را وارد نمایید.
|
شماره همراه خود را وارد نمایید.
|
||||||
</p>
|
</p>
|
||||||
<div className="mt-[16px] sm:mt-[19px] md:mt-[22px] lg:mt-[24px] mb-[40px] sm:mb-[37px] md:mb-[36px] lg:mb-[32px]">
|
<div className="mt-[16px] sm:mt-[19px] md:mt-[22px] lg:mt-[24px] mb-[19px] sm:mb-[16px] md:mb-[15px] lg:mb-[11px]">
|
||||||
<Field
|
<Field
|
||||||
dir="ltr"
|
dir="ltr"
|
||||||
value={num}
|
value={num}
|
||||||
type="number"
|
type="string"
|
||||||
|
error={error}
|
||||||
|
inputProps={{
|
||||||
|
startAdornment:
|
||||||
|
<InputAdornment
|
||||||
|
className="!ml-4"
|
||||||
|
position="start"
|
||||||
|
sx={{
|
||||||
|
'.MuiTypography-root': {
|
||||||
|
lineHeight: '0 !important',
|
||||||
|
},
|
||||||
|
'.muirtl-1qj5e5k-MuiTypography-root': {
|
||||||
|
color: '#000000de !important'
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>09</InputAdornment>,
|
||||||
|
}}
|
||||||
title="شماره همراه"
|
title="شماره همراه"
|
||||||
updateState={updateNum}
|
updateState={handleChange}
|
||||||
/>
|
/>
|
||||||
|
<p className={`text-[#d32f2f] text-[14px] mt-2 min-h-[21px] transition-all
|
||||||
|
${error ? 'opacity-100' : 'opacity-0'}
|
||||||
|
`}>{error}</p>
|
||||||
</div>
|
</div>
|
||||||
<Button
|
<Button
|
||||||
fullWidth
|
fullWidth
|
||||||
variant="contained"
|
variant="contained"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
|
const checkedNum = validatePhoneNumber(num);
|
||||||
|
if (!checkedNum.valid) {
|
||||||
|
setError(checkedNum.error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
setIsSendMsg && setIsSendMsg(true);
|
setIsSendMsg && setIsSendMsg(true);
|
||||||
setStep && setStep((prev) => prev + 1);
|
setStep && setStep((prev) => prev + 1);
|
||||||
}}
|
}}
|
||||||
|
|||||||
+23
-1
@@ -105,4 +105,26 @@ export const addLabelToList = (list) =>
|
|||||||
...item,
|
...item,
|
||||||
label: item.name
|
label: item.name
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export const formatPhoneNumber = (input) => {
|
||||||
|
const digits = input.replace(/\D/g, '');
|
||||||
|
const trimmed = digits.substring(0, 9);
|
||||||
|
const match = trimmed.match(/^(\d{0,2})(\d{0,3})(\d{0,4})$/);
|
||||||
|
if (!match) return trimmed;
|
||||||
|
return [match[1], match[2], match[3]].filter(Boolean).join(' ');
|
||||||
|
};
|
||||||
|
|
||||||
|
export function validatePhoneNumber(input) {
|
||||||
|
const digits = input.replace(/\D/g, '');
|
||||||
|
|
||||||
|
if (!digits) {
|
||||||
|
return { valid: false, error: 'شماره موبایل نمیتواند خالی باشد.' };
|
||||||
|
}
|
||||||
|
|
||||||
|
if (digits.length !== 9) {
|
||||||
|
return { valid: false, error: 'شماره موبایل باید دقیقا 11 رقم باشد.' };
|
||||||
|
}
|
||||||
|
|
||||||
|
return { valid: true, error: null };
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user