Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | 1x 28x 28x 28x 1x 1x 28x | import { Box, InputAdornment, Stack } from "@mui/material";
import { FormProvider } from "react-hook-form";
import NiceModal from "@ebay/nice-modal-react";
import { TERMS_OF_SERVICE_MODAL } from "modals/modal_names";
import GiveText from "@shared/Text/GiveText";
import {
EyeIcon,
EyeSlashIcon,
WarningOctagonIcon,
} from "@phosphor-icons/react";
import { useAppTheme } from "@theme/v2/Provider";
import { HFGiveInput } from "@shared/HFInputs/HFGiveInput/HFGiveInput";
import { sanitizePaste } from "@utils/index";
import { HFCheckbox } from "@shared/HFInputs/HFGiveCheckbox/HFGiveCheckbox";
import GiveLink from "@shared/Link/GiveLink";
import { Link } from "react-router-dom";
import GiveButton from "@shared/Button/GiveButton";
import type { UseFormReturn } from "react-hook-form";
import type { Location } from "react-router-dom";
import type { IFormInputs } from "@hooks/auth-api/types";
type Props = {
isLoading: boolean;
showAlert: string;
location: Location;
methods: UseFormReturn<IFormInputs>;
isPasswordVisible: boolean;
onSubmit: (data: IFormInputs) => void;
togglePasswordVisible: () => void;
};
const GiveLoginContent = ({
isLoading,
showAlert,
location,
methods,
isPasswordVisible,
onSubmit,
togglePasswordVisible,
}: Props) => {
const { palette } = useAppTheme();
const {
setValue,
formState: { isValid },
} = methods;
const openTermsConditions: React.MouseEventHandler<HTMLAnchorElement> = (
e,
) => {
e.preventDefault();
NiceModal.show(TERMS_OF_SERVICE_MODAL, {
agree: () =>
setValue("termsConditions", true, {
shouldDirty: true,
shouldValidate: true,
shouldTouch: true,
}),
});
};
return (
<Stack gap={"32px"}>
<Stack gap={"12px"}>
<GiveText variant="h3">Login</GiveText>
<GiveText variant="bodyM" color={"secondary"}>
Welcome back! We’re glad you’re here.
</GiveText>
</Stack>
{showAlert && (
<Stack
sx={{
gap: "12px",
padding: "12px",
alignItems: "center",
flexDirection: "row",
bgcolor: palette.primitive?.error[25],
borderRadius: "12px",
}}
>
<WarningOctagonIcon fill={palette.primitive?.error[100]} size={24} />
<GiveText fontSize="14px" color="error1">
{showAlert}
</GiveText>
</Stack>
)}
<FormProvider {...methods}>
<Box
component="form"
onSubmit={methods.handleSubmit(onSubmit)}
id="login"
>
<Stack gap={"24px"}>
<HFGiveInput name="email" label="Email" fullWidth handleNormalizeInput={sanitizePaste} />
<HFGiveInput
name="password"
fullWidth
type={isPasswordVisible ? "text" : "password"}
label="Password"
handleNormalizeInput={sanitizePaste}
autoFocus={Boolean((location.state as any)?.alert)}
InputProps={{
endAdornment: (
<InputAdornment
onClick={togglePasswordVisible}
position="end"
sx={{ cursor: "pointer" }}
>
{isPasswordVisible ? (
<EyeIcon
size={20}
color={palette.icon?.["icon-primary"]}
/>
) : (
<EyeSlashIcon
size={20}
color={palette.icon?.["icon-primary"]}
/>
)}
</InputAdornment>
),
}}
/>
<Stack gap={"11px"}>
<Stack direction="row" justifyContent="space-between">
<HFCheckbox label="Remember me" name="remember" />
<GiveLink
component={Link}
link="/reset-password"
data-testid="forgot-password-link"
variant="bodyS"
>
Forgot Password?
</GiveLink>
</Stack>
<HFCheckbox
name="termsConditions"
label={
<Stack direction="row" gap="3px">
<GiveText variant="bodyS">I accept the</GiveText>
<GiveLink
variant="bodyS"
component="button"
onClick={openTermsConditions}
sx={{
textDecoration: "underline",
textUnderlineOffset: "3px",
"& span:before": { display: "none" },
"&:hover span:before": { display: "none" },
}}
>
Terms & Conditions
</GiveLink>
</Stack>
}
/>
</Stack>
</Stack>
</Box>
</FormProvider>
<GiveButton
label="Login"
size="large"
disabled={!isValid || isLoading}
type="submit"
form="login"
sx={{ width: "fit-content", ml: "auto" }}
/>
</Stack>
);
};
export default GiveLoginContent;
|