|
| 1 | +import React, { useState } from "react"; |
| 2 | +import styled from "styled-components"; |
| 3 | +import { Checkbox, Button } from "@kleros/ui-components-library"; |
| 4 | +import FormEmail from "./FormEmail"; |
| 5 | + |
| 6 | +const FormContainer = styled.div` |
| 7 | + position: relative; |
| 8 | + display: flex; |
| 9 | + flex-direction: column; |
| 10 | + padding: 0 calc(12px + (32 - 12) * ((100vw - 300px) / (1250 - 300))); |
| 11 | + padding-bottom: 32px; |
| 12 | +`; |
| 13 | + |
| 14 | +const StyledCheckbox = styled(Checkbox)` |
| 15 | + margin-top: 20px; |
| 16 | +`; |
| 17 | + |
| 18 | +const ButtonContainer = styled.div` |
| 19 | + display: flex; |
| 20 | + justify-content: end; |
| 21 | + margin-top: 16px; |
| 22 | +`; |
| 23 | + |
| 24 | +const FormEmailContainer = styled.div` |
| 25 | + position: relative; |
| 26 | +`; |
| 27 | + |
| 28 | +const EmailErrorContainer = styled.div` |
| 29 | + position: absolute; |
| 30 | + color: ${({ theme }) => theme.error}; |
| 31 | + font-size: 12px; |
| 32 | + padding-top: 4px; |
| 33 | + padding-left: 16px; |
| 34 | +`; |
| 35 | + |
| 36 | +const OPTIONS = [{ label: "When x." }, { label: "When y." }, { label: "When z." }, { label: "When w." }]; |
| 37 | + |
| 38 | +const FormNotifs: React.FC = () => { |
| 39 | + const [checkboxStates, setCheckboxStates] = useState<boolean[]>(new Array(OPTIONS.length)); |
| 40 | + const [emailInput, setEmailInput] = useState<string>(""); |
| 41 | + const [emailIsValid, setEmailIsValid] = useState<boolean>(false); |
| 42 | + |
| 43 | + const handleCheckboxChange = (index: number) => (e: React.ChangeEvent<HTMLInputElement>) => { |
| 44 | + const newCheckboxStates = [...checkboxStates]; |
| 45 | + newCheckboxStates[index] = e.target.checked; |
| 46 | + setCheckboxStates(newCheckboxStates); |
| 47 | + }; |
| 48 | + |
| 49 | + return ( |
| 50 | + <FormContainer> |
| 51 | + {OPTIONS.map(({ label }, index) => ( |
| 52 | + <StyledCheckbox |
| 53 | + key={label} |
| 54 | + onChange={handleCheckboxChange(index)} |
| 55 | + checked={checkboxStates[index]} |
| 56 | + small={true} |
| 57 | + label={label} |
| 58 | + /> |
| 59 | + ))} |
| 60 | + <FormEmailContainer> |
| 61 | + <FormEmail |
| 62 | + emailInput={emailInput} |
| 63 | + emailIsValid={emailIsValid} |
| 64 | + setEmailInput={setEmailInput} |
| 65 | + setEmailIsValid={setEmailIsValid} |
| 66 | + /> |
| 67 | + </FormEmailContainer> |
| 68 | + |
| 69 | + <ButtonContainer> |
| 70 | + <Button text="Save" disabled={!emailIsValid} /> |
| 71 | + </ButtonContainer> |
| 72 | + </FormContainer> |
| 73 | + ); |
| 74 | +}; |
| 75 | + |
| 76 | +export default FormNotifs; |
0 commit comments