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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. import PropTypes, { func } from 'prop-types';
  2. import axios from 'axios';
  3. import OrbitOnClick from './graphics/OrbitOnClick';
  4. import Animation_Diligent from '../../assets/animation_diligent.webm';
  5. import { Tab } from '@headlessui/react';
  6. import { useState, useContext, useEffect } from 'react';
  7. import ClientForm from './ClientForm';
  8. import JobForm from './JobForm';
  9. import { ClientFormContext } from '../../context';
  10. import { JobFormContext } from '../../context';
  11. import PageTitle from './PageTitle';
  12. import Wrapper from '../../layout/Wrapper';
  13. import { UIContext } from './../../context/index';
  14. import Mailgun from 'mailgun.js';
  15. import FormData from 'form-data';
  16. const mailgun = new Mailgun(FormData);
  17. const mg = mailgun.client({
  18. username: 'api',
  19. key: process.env.REACT_APP_MAILGUN_API_KEY,
  20. url: 'https://api.eu.mailgun.net',
  21. });
  22. export default function Contact({job, business, defaultIndex}) {
  23. const [tab, setTab] = useState(true);
  24. const [tabTitle, setTabTitle] = useState(business.title);
  25. function handleContextMenu(event) {
  26. event.preventDefault();
  27. }
  28. function handleTabClick(event) {
  29. //if (event.button !== 0)
  30. event.preventDefault();
  31. }
  32. const { uiContext, setUiContext } = useContext(UIContext);
  33. const clientContext = useContext(ClientFormContext);
  34. const jobContext = useContext(JobFormContext);
  35. function classNames(...classes) {
  36. return classes.filter(Boolean).join(' ');
  37. }
  38. function handleTab(tabIndex) {
  39. if (tabIndex == 0) {
  40. setTab(true);
  41. setTabTitle(business.title);
  42. } else {
  43. setTab(false);
  44. setTabTitle(job.title);
  45. }
  46. }
  47. const initialClientValues = clientContext ?? {
  48. tag: '',
  49. subject: '',
  50. firstName: '',
  51. lastName: '',
  52. email: '',
  53. description: '',
  54. };
  55. const initialJobValues = jobContext ?? {
  56. position: '',
  57. other: '',
  58. firstName: '',
  59. lastName: '',
  60. email: '',
  61. description: '',
  62. files: [],
  63. };
  64. const api_url = process.env.REACT_APP_API_URL;
  65. let defaultPositionSelection = null;
  66. const [clientForm, setClientForm] = useState(initialClientValues);
  67. const [jobForm, setJobForm] = useState(initialJobValues);
  68. const [cntCareers, setCntCareers] = useState('');
  69. const [isLoaded, setIsLoaded] = useState('');
  70. useEffect(async () => {
  71. var vid = document.getElementById('animation');
  72. vid.playbackRate = 2;
  73. axios
  74. .get(
  75. `${api_url}/api/careerspage?populate[0]=heading&populate[1]=info&populate[2]=job.icon`,
  76. )
  77. .then(res => {
  78. //console.log(res.data.data.attributes);
  79. setCntCareers(res.data.data.attributes);
  80. setIsLoaded(true);
  81. })
  82. .catch(err => {
  83. console.log(err);
  84. setIsLoaded(false);
  85. });
  86. }, []);
  87. if (!isLoaded) {
  88. return (
  89. <div className="z-50 w-full h-screen bg-white dark:bg-dg-primary-1700 dark:text-white flex items-center justify-center text-3xl font-semibold">
  90. <video id="animation" width="540" height="540" autoPlay muted loop>
  91. <source src={Animation_Diligent} type="video/webm" />
  92. Loading...
  93. </video>
  94. </div>
  95. );
  96. }
  97. return (
  98. <Wrapper bg>
  99. <div className="absolute top-40 md:top-8 right-11 md:right-12 z-10">
  100. <OrbitOnClick tab={tab} />
  101. </div>
  102. <div className="py-16 relative">
  103. <div className="flex justify-end flex-col">
  104. <Tab.Group
  105. defaultIndex={defaultIndex}
  106. onChange={index => handleTab(index)}
  107. >
  108. <div
  109. className="flex flex-col md:flex-row items-start md:items-baseline md:justify-between"
  110. onMouseDown={handleTabClick}
  111. >
  112. {tab ? (
  113. <PageTitle
  114. left
  115. heading={business.title}
  116. subheading={business.subtitle}
  117. />
  118. ) : (
  119. <PageTitle left heading={job.title} subheading={job.title} />
  120. )}
  121. <Tab.List className="flex flex-row items-center md:flex-col lg:flex-row h-fit w-fit max-w-max md:ml-auto z-20 p-1 min-h-12 space-x-1 bg-dg-primary-400 rounded-xl my-4 align-middle">
  122. <Tab
  123. className={({ selected }) =>
  124. classNames(
  125. 'h-fit w-fit py-2 px-4 text-sm leading-5 font-medium text-dg-primary-900 rounded-lg',
  126. 'focus:outline-none ',
  127. selected
  128. ? 'bg-white shadow'
  129. : 'text-blue-100 hover:bg-white/[0.12] hover:text-white',
  130. )
  131. }
  132. >
  133. Business Inquiry
  134. </Tab>
  135. <Tab
  136. className={({ selected }) =>
  137. classNames(
  138. 'h-fit w-fit py-2 px-4 text-sm leading-5 font-medium text-dg-primary-900 rounded-lg',
  139. 'focus:outline-none',
  140. selected
  141. ? 'bg-white shadow'
  142. : 'text-blue-100 hover:bg-white/[0.12] hover:text-white',
  143. )
  144. }
  145. >
  146. Apply for a position
  147. </Tab>
  148. </Tab.List>
  149. </div>
  150. <Tab.Panels className="w-full mt-2 mx-auto">
  151. <Tab.Panel className={classNames('py-3', 'outline-none')}>
  152. <ClientFormContext.Provider value={{ clientForm, setClientForm }}>
  153. <ClientForm mg={mg}
  154. cta={business.cta}
  155. img={business.image} />
  156. </ClientFormContext.Provider>
  157. </Tab.Panel>
  158. <Tab.Panel className={classNames('py-3', 'outline-none')}>
  159. <JobFormContext.Provider value={{ jobForm, setJobForm }}>
  160. <JobForm
  161. cta={job.cta}
  162. img={job.image}
  163. cntCareers={cntCareers}
  164. defaultPositionSelection={defaultPositionSelection}
  165. mg={mg}
  166. />
  167. </JobFormContext.Provider>
  168. </Tab.Panel>
  169. </Tab.Panels>
  170. </Tab.Group>
  171. </div>
  172. </div>
  173. </Wrapper>
  174. );
  175. }
  176. Contact.propTypes = {
  177. setTab: PropTypes.func,
  178. tabTitle: PropTypes.string,
  179. setTabTitle: PropTypes.func,
  180. defaultIndex: PropTypes.number,
  181. defaultPositionSelection: PropTypes.string,
  182. };