baby_in_magento

fbehjfej

Apr 15th, 2024
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.70 KB | None | 0 0
  1. import React, { Fragment, useEffect, useState } from 'react';
  2. import { FormattedMessage, useIntl } from 'react-intl';
  3. import { shape, string } from 'prop-types';
  4. import { Form } from 'informed';
  5.  
  6. import { useToasts } from '@magento/peregrine';
  7. import { useContactPage } from '@magento/peregrine/lib/talons/ContactPage';
  8.  
  9. import { useStyle } from '@magento/venia-ui/lib/classify';
  10. import { isRequired } from '@magento/venia-ui/lib/util/formValidators';
  11.  
  12.  
  13. import CmsBlock from '@magento/venia-ui/lib/components/CmsBlock/block';
  14. import { Meta, StoreTitle } from '@magento/venia-ui/lib/components/Head';
  15. import FormError from '@magento/venia-ui/lib/components/FormError';
  16. import Field from '../Field';
  17. import TextInput from '../TextInput';
  18. import TextArea from '@magento/venia-ui/lib/components/TextArea';
  19. import LoadingIndicator from '../LoadingIndicator';
  20. import ErrorView from '@magento/venia-ui/lib/components/ErrorView';
  21. import ContactPageShimmer from './contactPage.shimmer';
  22. import defaultClasses from '@magento/venia-ui/lib/components/ContactPage/contactPage.module.css';
  23. import phone from './images/phone.svg';
  24. import location from './images/location.svg';
  25. import facebook from './images/facebook.svg';
  26. import instagram from './images/instagram.svg';
  27. import whatsapp from './images/whatsapp.png';
  28. import email from './images/email.png';
  29. import twitter from './images/twitter.svg';
  30. import youtube from './images/youtube.svg';
  31. import Button from '../Button';
  32. import apiClient from '../../api';
  33.  
  34. import {Link } from "react-router-dom";
  35.  
  36.  
  37. const BANNER_IDENTIFIER = 'contact-us-banner';
  38. const SIDEBAR_IDENTIFIER = 'contact-us-sidebar';
  39. const NOT_FOUND_MESSAGE =
  40. "Looks like the page you were hoping to find doesn't exist. Sorry about that.";
  41.  
  42. const ContactPage = props => {
  43. const { classes: propClasses } = props;
  44. const classes = useStyle(defaultClasses, propClasses);
  45. const { formatMessage } = useIntl();
  46. const talonProps = useContactPage({
  47. cmsBlockIdentifiers: [BANNER_IDENTIFIER, SIDEBAR_IDENTIFIER]
  48. });
  49. const [, { addToast }] = useToasts();
  50. const {
  51. isEnabled,
  52. cmsBlocks,
  53. errors,
  54. handleSubmit,
  55. isBusy,
  56. isLoading,
  57. setFormApi,
  58. response
  59. } = talonProps;
  60.  
  61. const [contactInfo, setContactInfo] = useState()
  62.  
  63. const [userName, setUserName] = useState('');
  64.  
  65. const [mobileNumber, setPhoneNumber] = useState('');
  66.  
  67. const [email, setEmail] = useState('');
  68.  
  69. const [message, setMessage] = useState('');
  70.  
  71.  
  72. const getContactDetails = async () => {
  73. try {
  74. const response = await apiClient.get(apiClient.Urls.getSlider, {
  75. identifier: 'contact_info'
  76. });
  77. if (response.success) {
  78. setContactInfo(response.data);
  79. }
  80. } catch (error) {
  81. console.log('error', error);
  82. }
  83. };
  84.  
  85.  
  86.  
  87. const submitContactUsForm = async () => {
  88.  
  89. try {
  90.  
  91. const response = await apiClient.post(
  92.  
  93. apiClient.Urls.contactUsForm,
  94.  
  95. {
  96.  
  97. params: {
  98.  
  99. name:userName,
  100.  
  101. mobile_number:mobileNumber,
  102.  
  103. email:email,
  104.  
  105. message:message
  106.  
  107. }
  108.  
  109. },
  110.  
  111. );
  112.  
  113. if (response.data && response.data.success == true) {
  114.  
  115. console.log(response.message);
  116.  
  117. }
  118.  
  119. } catch (error) {
  120.  
  121. console.log('error', error);
  122.  
  123. }
  124.  
  125. };
  126.  
  127. useEffect(() => {
  128. getContactDetails()
  129. }, [])
  130.  
  131. const phoneNumber = contactInfo && contactInfo.find(i => i.slide_title === "phone_number");
  132.  
  133. const whatsappNumber = contactInfo && contactInfo.find(i => i.slide_title === "whatsapp_number");
  134.  
  135. const mailId = contactInfo && contactInfo.find(i => i.slide_title === "email_id");
  136.  
  137. const addressInfo = contactInfo && contactInfo.find(i => i.slide_title === "address_info");
  138.  
  139. useEffect(() => {
  140. if (response && response.status) {
  141. addToast({
  142. type: 'success',
  143. message: formatMessage({
  144. id: 'contactPage.submitMessage',
  145. defaultMessage: 'Your message has been sent.'
  146. }),
  147. timeout: 5000
  148. });
  149. }
  150. }, [addToast, formatMessage, response]);
  151.  
  152. if (!isLoading && !isEnabled) {
  153. return (
  154. <Fragment>
  155. <StoreTitle>
  156. {formatMessage({
  157. id: 'contactPage.title',
  158. defaultMessage: 'Contact Us'
  159. })}
  160. </StoreTitle>
  161. <ErrorView
  162. message={formatMessage({
  163. id: 'magentoRoute.routeError',
  164. defaultMessage: NOT_FOUND_MESSAGE
  165. })}
  166. />
  167. </Fragment>
  168. );
  169. }
  170.  
  171. if (isLoading) {
  172. return <ContactPageShimmer />;
  173. }
  174.  
  175. const maybeLoadingIndicator = isBusy ? (
  176. <div className={classes.loadingContainer}>
  177. <LoadingIndicator>
  178. <FormattedMessage
  179. id={'contactPage.loadingText'}
  180. defaultMessage={'Sending'}
  181. />
  182. </LoadingIndicator>
  183. </div>
  184. ) : null;
  185.  
  186. const contactUsBannerContent = cmsBlocks.find(
  187. item => item.identifier === BANNER_IDENTIFIER
  188. )?.content;
  189.  
  190. const contactUsBanner = contactUsBannerContent ? (
  191. <div className={classes.banner}>
  192. <CmsBlock content={contactUsBannerContent} />
  193. </div>
  194. ) : null;
  195.  
  196. const contactUsSidebarContent = cmsBlocks.find(
  197. item => item.identifier === SIDEBAR_IDENTIFIER
  198. )?.content;
  199.  
  200. const contactUsSidebar = contactUsSidebarContent ? (
  201. <div className={classes.sideContent}>
  202. <CmsBlock content={contactUsSidebarContent} />
  203. </div>
  204. ) : null;
  205.  
  206. const pageTitle = formatMessage({
  207. id: 'contactPage.title',
  208. defaultMessage: 'Contact Us'
  209. });
  210.  
  211. const metaDescription = formatMessage({
  212. id: 'contactPage.metaDescription',
  213. defaultMessage: 'Contact Us'
  214. });
  215.  
  216. return (
  217. <Fragment>
  218. <StoreTitle>{pageTitle}</StoreTitle>
  219. <Meta name="title" content={pageTitle} />
  220. <Meta name="description" content={metaDescription} />
  221. <article className={classes.root} data-cy="ContactPage-root">
  222. {contactUsBanner}
  223. <div className={classes.content + ' contact-content'}>
  224. <div className='bg-[#FCFAFB] contact-main rounded-lg'>
  225. <div className='contact-container'>
  226. <h3 className='ivymode-regular text-[42px]
  227. text-[#774E4F] contact-section'>Contact Details</h3>
  228. <p className='text-[#3B444D] text-[14px] font-lato regular'>Find our contact number and other details</p>
  229. </div>
  230. <section className='contact_details_section px-[20px]'>
  231. <a target={'_blank'} href="tel:18001212511" className='flex phone-section items-center'>
  232. <img src={phone} alt='phone' className='phone_section' />
  233. <p className='text-[#181A1D]'>{phoneNumber?.mapping_value}</p>
  234. </a>
  235. <a target={"_blank"} href="https://wa.me/+916379337011" className='flex phone-section items-center'>
  236. <img src={whatsapp} alt='phone' className='phone_section' style={{ width: 50, height: 50 }} />
  237. <p className='text-[#181A1D]'>{whatsappNumber?.mapping_value}</p>
  238. </a>
  239. <a target={'_blank'} href="mailto:[email protected]" className='flex items-center'>
  240. <img src={email} alt='phone' className='phone_section' style={{ width: 50, height: 50 }} />
  241. <p className='text-[#181A1D]'>{mailId?.mapping_value}</p>
  242. </a>
  243. <div className='flex items-center'>
  244. <img src={location} alt='location' className='phone_section' />
  245. <div className='text-[#181A1D]'>
  246. <p>{addressInfo?.mapping_value}</p>
  247. {/* <p>KIRTILAL KALIDAS JEWELLERS PVT. LTD.</p>
  248. <p>GN Mills Post, Mettupalayam Road, Coimbatore</p>
  249. <p>Tamilnadu-641029</p> */}
  250. </div>
  251. </div>
  252. </section>
  253. <section className='social_linking pb-[20px]'>
  254. <p className='text-[#293036] text-center mt-[3rem] mb-4 text-[14px] font-lato regular get-social'>Let’s get social</p>
  255. <div className='flex justify-evenly cursor-pointer'>
  256. <a target={"_blank"} href="https://www.facebook.com/Glowjewelsonline/"><img src={facebook} alt='facebook' /></a>
  257. <a target={"_blank"} href="https://www.instagram.com/Glowjewelsonline/"><img src={instagram} alt='instagram' /></a>
  258. <a target={"_blank"} href="https://twitter.com/Glowjewelonline/"><img src={twitter} alt='twitter' /></a>
  259. <a target={"_blank"} href="https://www.youtube.com/@glowjewelsonline"><img src={youtube} alt='youtube' /></a>
  260. </div>
  261. </section>
  262. </div>
  263. <div
  264. className={classes.formContainer + ' contactpage-form'}
  265. data-cy="ContactPage-formContainer"
  266. >
  267. {maybeLoadingIndicator}
  268. <h1 className={classes.title + ' ivymode-regular text-[42px] text-[#774E4F] send-us-section'}>
  269. {/* <FormattedMessage
  270. id={'contactPage.titleText'}
  271. defaultMessage={'Contact Us'}
  272. /> */}
  273. Send Us A Message
  274. </h1>
  275.  
  276. <p className={classes.subtitle + ' text-[#3B444D] font-lato regular text-[14px] text-center'}>
  277. {/* <FormattedMessage
  278. id={'contactPage.infoText'}
  279. defaultMessage={`Drop us a line and we'll get back to you as soon as possible.`}
  280. /> */}
  281. Please enter the details to hear back from us!
  282. </p>
  283. <FormError
  284. allowErrorMessages
  285. errors={Array.from(errors.values())}
  286. />
  287. <Form
  288. getApi={setFormApi}
  289. className={classes.form}
  290. onSubmit={handleSubmit}
  291. >
  292. <div className='send-message-field'>
  293. <section className='send-message'>
  294. {/* <Field
  295. id="contact-name"
  296. className='contact-form-field'
  297. label={formatMessage({
  298. id: 'global.name',
  299. defaultMessage: 'Name'
  300. })}
  301. > */}
  302. <TextInput
  303. autoComplete="name"
  304. field="name"
  305. id="contact-name"
  306. validate={isRequired}
  307. data-cy="name"
  308. placeholder='Name'
  309. className='name-field'
  310. onValueChange={(value)=>setUserName(value)}
  311. />
  312. </section>
  313. {/* </Field> */}
  314. {/* <Field
  315. id="contact-email"
  316. label={formatMessage({
  317. id: 'global.email',
  318. defaultMessage: 'Email'
  319. })}
  320. > */}
  321. <section className='send-message'>
  322. <TextInput
  323. autoComplete="email"
  324. field="email"
  325. id="contact-email"
  326. validate={isRequired}
  327. // placeholder={formatMessage({
  328. // id: 'global.emailPlaceholder',
  329. // defaultMessage: '[email protected]'
  330. // })}
  331. data-cy="email"
  332. placeholder='Email'
  333. onValueChange={(value)=>setEmail(value)}
  334. />
  335. </section>
  336. </div>
  337. {/* </Field> */}
  338. {/* <Field
  339. id="contact-telephone"
  340. label={formatMessage({
  341. id: 'contactPage.telephone',
  342. defaultMessage: 'Phone Number'
  343. })}
  344. optional={true}
  345. > */}
  346. <TextInput
  347. autoComplete="tel"
  348. field="telephone"
  349. id="contact-telephone"
  350. validate={isRequired}
  351. // placeholder={formatMessage({
  352. // id: 'contactPage.telephonePlaceholder',
  353. // defaultMessage: '(222)-222-2222'
  354. // })}
  355. data-cy="telephone"
  356. placeholder='Phone number'
  357. onValueChange={(value)=>setPhoneNumber(value)}
  358. />
  359. {/* </Field> */}
  360. {/* <Field
  361. id="contact-comment"
  362. label={formatMessage({
  363. id: 'contactPage.comment',
  364. defaultMessage: 'Message'
  365. })}
  366. > */}
  367. <TextArea
  368. autoComplete="comment"
  369. field="comment"
  370. id="contact-comment"
  371. validate={isRequired}
  372. // placeholder={formatMessage({
  373. // id: 'contactPage.commentPlaceholder',
  374. // defaultMessage: `Tell us what's on your mind`
  375. // })}
  376. data-cy="comment"
  377. placeholder='write a message'
  378. onValueChange={(value)=>setMessage(value)}
  379. />
  380. {/* </Field> */}
  381. <div className={classes.buttonsContainer + ' button_container'}>
  382. <Link to="/thank-you">
  383. <Button
  384. priority="high"
  385. type="submit"
  386. disabled={isBusy}
  387. data-cy="submit"
  388. className='submit-button'
  389. onClick={()=>{
  390.  
  391. submitContactUsForm()
  392.  
  393. }}
  394. >
  395. {/* <FormattedMessage
  396. id={'contactPage.submit'}
  397. defaultMessage={'Send'}
  398. /> */}
  399. submit
  400. </Button>
  401. </Link>
  402. </div>
  403. </Form>
  404. </div>
  405. {contactUsSidebar}
  406. </div>
  407. </article>
  408. </Fragment>
  409. );
  410. };
  411.  
  412. ContactPage.propTypes = {
  413. classes: shape({
  414. loadingContainer: string,
  415. banner: string,
  416. sideContent: string,
  417. root: string,
  418. content: string,
  419. formContainer: string,
  420. title: string,
  421. subtitle: string,
  422. form: string,
  423. buttonsContainer: string
  424. })
  425. };
  426.  
  427. export default ContactPage;
  428.  
Advertisement
Add Comment
Please, Sign In to add comment