|
| 1 | +import { getNames } from 'country-list'; |
| 2 | +import moment from 'moment'; |
| 3 | +import PropTypes from 'prop-types'; |
| 4 | +import React from 'react'; |
| 5 | +import { useFormContext } from 'react-hook-form'; |
| 6 | + |
| 7 | +import Input from '../../../shared/button/input'; |
| 8 | +import Select from '../../../shared/button/select'; |
| 9 | + |
| 10 | +const Form = ({ info }) => { |
| 11 | + const { |
| 12 | + register, |
| 13 | + formState: { errors, isSubmitSuccessful }, |
| 14 | + } = useFormContext(); |
| 15 | + return ( |
| 16 | + <> |
| 17 | + <div> |
| 18 | + Select Prizes to claim: |
| 19 | + {info.map((winner) => ( |
| 20 | + <div className="mt-2 flex"> |
| 21 | + <div> |
| 22 | + <input |
| 23 | + disabled={isSubmitSuccessful} |
| 24 | + {...register('type', { required: true })} |
| 25 | + name="type" |
| 26 | + value={winner.id} |
| 27 | + type="checkbox" |
| 28 | + /> |
| 29 | + </div> |
| 30 | + <div className="ml-2"> |
| 31 | + {winner.type === 'COMPETITION' && 'Competition Winner'} |
| 32 | + {winner.type === 'NOVU' && 'Novu Swag Claim'} |
| 33 | + {winner.type === 'EXTRA' && 'Giveaway or other'} - Expires on{' '} |
| 34 | + {moment.utc(winner.lastDateClaim).local().format('DD/MM/YYYY HH:mm')} |
| 35 | + </div> |
| 36 | + </div> |
| 37 | + ))} |
| 38 | + {!!errors.type && ( |
| 39 | + <div className="mt-3" style={{ color: 'red' }}> |
| 40 | + You must select a prize to claim |
| 41 | + </div> |
| 42 | + )} |
| 43 | + </div> |
| 44 | + <Input |
| 45 | + name="first_name" |
| 46 | + extra={{ minLength: 2, required: true }} |
| 47 | + label="First Name" |
| 48 | + type="text" |
| 49 | + /> |
| 50 | + <Input |
| 51 | + extra={{ minLength: 2, required: true }} |
| 52 | + label="Last Name" |
| 53 | + type="text" |
| 54 | + name="last_name" |
| 55 | + /> |
| 56 | + <Input |
| 57 | + extra={{ |
| 58 | + required: true, |
| 59 | + pattern: /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/i, |
| 60 | + }} |
| 61 | + label="Email" |
| 62 | + type="text" |
| 63 | + name="email" |
| 64 | + /> |
| 65 | + <Input |
| 66 | + label="Phone Number" |
| 67 | + type="text" |
| 68 | + name="phone_number" |
| 69 | + placeHolder="+972" |
| 70 | + extra={{ |
| 71 | + required: true, |
| 72 | + pattern: |
| 73 | + /\+(9[976]\d|8[987530]\d|6[987]\d|5[90]\d|42\d|3[875]\d|2[98654321]\d|9[8543210]|8[6421]|6[6543210]|5[87654321]|4[987654310]|3[9643210]|2[70]|7|1)\d{1,14}$/i, |
| 74 | + }} |
| 75 | + /> |
| 76 | + <Input |
| 77 | + extra={{ minLength: 5, required: true }} |
| 78 | + label="Address" |
| 79 | + type="text" |
| 80 | + name="shipping_address1" |
| 81 | + /> |
| 82 | + <Input label="Address 2" type="text" name="shipping_address2" /> |
| 83 | + <Input |
| 84 | + extra={{ required: true, minLength: 2 }} |
| 85 | + label="City" |
| 86 | + type="text" |
| 87 | + name="shipping_city" |
| 88 | + /> |
| 89 | + <Select label="Country" name="shipping_country"> |
| 90 | + <option value="">-- Choose Country --</option> |
| 91 | + {getNames().map((c) => ( |
| 92 | + <option value={c}>{c}</option> |
| 93 | + ))} |
| 94 | + </Select> |
| 95 | + <Input extra={{ required: true }} label="State" type="text" name="shipping_state" /> |
| 96 | + <Input extra={{ required: true, minLength: 3 }} label="ZIP" type="text" name="shipping_zip" /> |
| 97 | + <Select label="Shirt Size" name="shirt_size"> |
| 98 | + <option value="">-- Choose Shirt Size --</option> |
| 99 | + <option value="Small">Small</option> |
| 100 | + <option value="Medium">Medium</option> |
| 101 | + <option value="Large">Large</option> |
| 102 | + <option value="X-Large">Extra Large</option> |
| 103 | + <option value="2X-Large">2 Extra Large</option> |
| 104 | + </Select> |
| 105 | + <button |
| 106 | + type="submit" |
| 107 | + disabled={isSubmitSuccessful} |
| 108 | + className={`${ |
| 109 | + isSubmitSuccessful && 'pointer-events-none opacity-50' |
| 110 | + } cta-btn-animation relative flex max-w-full cursor-pointer items-center justify-center leading-none`} |
| 111 | + > |
| 112 | + <svg |
| 113 | + className="cta-btn-animation-border xs:w-full" |
| 114 | + width="200" |
| 115 | + height="59" |
| 116 | + viewBox="0 0 268 59" |
| 117 | + fill="none" |
| 118 | + > |
| 119 | + <path d="M1 58V1H251.586L267 16.4142V58H1Z" stroke="white" strokeWidth="2" /> |
| 120 | + </svg> |
| 121 | + |
| 122 | + <div className="absolute inset-0 flex items-center justify-center space-x-2.5"> |
| 123 | + <span className="text-lg sm:text-[18px]">Claim Swag!</span> |
| 124 | + </div> |
| 125 | + </button> |
| 126 | + </> |
| 127 | + ); |
| 128 | +}; |
| 129 | + |
| 130 | +Form.propTypes = { |
| 131 | + info: PropTypes.object, |
| 132 | +}; |
| 133 | + |
| 134 | +export default Form; |
0 commit comments