You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

WorkClientForm.jsx 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. import React from 'react';
  2. import CustomLink from './root/CustomLink';
  3. import * as Yup from 'yup';
  4. import { Formik, Form, ErrorMessage } from 'formik';
  5. import { useState, useRef } from 'react';
  6. const WorkClientForm = ({ data, download, onValidated, message, status }) => {
  7. const container = useRef();
  8. const [suc, setSuc] = useState(false);
  9. const [form, setForm] = useState({
  10. name: '',
  11. surname: '',
  12. email: '',
  13. });
  14. const validationSchema = Yup.object({
  15. name: Yup.string()
  16. .min(2, 'First name too short')
  17. .max(50, 'First name too long')
  18. .required('First Name is Required'),
  19. email: Yup.string().email('Invalid email format').required('Email is Required'),
  20. surname: Yup.string()
  21. .min(2, 'Last name too short')
  22. .max(50, 'Last name too long')
  23. .required('Last Name is Required'),
  24. });
  25. return (
  26. <div ref={container} className="max-w-[600px] mx-[16px] md:mx-auto md:mt-[-320px] p-[24px] flex flex-col gap-[24px] z-20 bg-white rounded-[16px] shadow-[0_3px_10px_rgb(0,0,0,0.2)] md:shadow-none">
  27. <div className="flex flex-col gap-[8px]">
  28. <h6 className="n-h3-heading text-dark-gray font-bold">{data.title}</h6>
  29. <p className="n-paragraph">{data.paragraph}</p>
  30. <Formik
  31. initialValues={form}
  32. validationSchema={validationSchema}
  33. onSubmit={async values => {
  34. setForm({
  35. ...form,
  36. name: values.name,
  37. surname: values.surname,
  38. email: values.email,
  39. });
  40. onValidated({
  41. FNAME: values.name,
  42. LNAME: values.surname,
  43. EMAIL: values.email,
  44. });
  45. }}
  46. >
  47. {props => (
  48. <Form onSubmit={props.handleSubmit}>
  49. <div className=" sm:rounded-md">
  50. <div className="py-2 sm:py-6">
  51. <div className="">
  52. <div className="col-span-1 sm:col-span-1">
  53. <div className="py-1">
  54. <label
  55. htmlFor="name"
  56. className="block text-sm font-medium text-gray-700 dark:text-gray-400"
  57. >
  58. First name
  59. </label>
  60. <input
  61. type="text"
  62. name="name"
  63. id="name"
  64. onChange={props.handleChange}
  65. value={props.values.name}
  66. autoComplete="given-name"
  67. className="mt-1 focus:ring-dg-primary-600 focus:border-dg-primary-900 dark:bg-dg-primary-1500 dark:text-white block w-full shadow-sm sm:text-sm border-dg-primary-600 rounded-md transition duration-200"
  68. />
  69. <div className="h-4">
  70. <ErrorMessage
  71. name="name"
  72. component="div"
  73. className="text-sm text-right text-red-600"
  74. />
  75. </div>
  76. </div>
  77. <div className="py-1">
  78. <label
  79. htmlFor="surname"
  80. className="block text-sm font-medium text-gray-700 dark:text-gray-400"
  81. >
  82. Last name
  83. </label>
  84. <input
  85. type="text"
  86. name="surname"
  87. id="surname"
  88. onChange={props.handleChange}
  89. value={props.values.surname}
  90. autoComplete="family-name"
  91. className="mt-1 focus:ring-dg-primary-900 focus:border-dg-primary-900 dark:bg-dg-primary-1500 dark:text-white block w-full shadow-sm sm:text-sm border-dg-primary-600 rounded-md transition duration-200"
  92. />
  93. <div className="h-4">
  94. <ErrorMessage
  95. name="surname"
  96. component="div"
  97. className="text-sm text-right text-red-600"
  98. />
  99. </div>
  100. </div>
  101. <div className="py-1">
  102. <label
  103. htmlFor="email"
  104. className="block text-sm font-medium text-gray-700 dark:text-gray-400"
  105. >
  106. Email
  107. </label>
  108. <input
  109. type="email"
  110. name="email"
  111. id="email"
  112. onChange={props.handleChange}
  113. value={props.values.email}
  114. autoComplete="email"
  115. className="mt-1 focus:ring-dg-primary-900 focus:border-dg-primary-900 dark:bg-dg-primary-1500 dark:text-white dark:autofill:text-white dark:autofill:bg-dg-primary-1500 block w-full shadow-sm sm:text-sm border-dg-primary-600 rounded-md transition duration-200"
  116. />
  117. <div className="h-4">
  118. <ErrorMessage
  119. name="email"
  120. component="div"
  121. className="text-sm text-right text-red-600"
  122. />
  123. </div>
  124. </div>
  125. <div className=" py-3 text-right">
  126. <button type="submit">
  127. <CustomLink
  128. href={download.downloadFilePath}
  129. downloadFile={download.downloadFileName}
  130. context={'Company Overview'}
  131. submit
  132. >
  133. Subscribe and Download
  134. </CustomLink>
  135. </button>
  136. <div>{message}</div>
  137. <div>{status}</div>
  138. </div>
  139. </div>
  140. </div>
  141. </div>
  142. </div>
  143. </Form>
  144. )}
  145. </Formik>
  146. </div>
  147. </div>
  148. );
  149. };
  150. export default WorkClientForm;