All files / pages contact.js

0% Statements 0/14
0% Branches 0/8
0% Functions 0/5
0% Lines 0/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192                                                                                                                                                                                                                                                                                                                                                                                               
import DottedLine from '../components/DottedLine'
import en from '../locales/contact/en'
import fr from '../locales/contact/fr'
import { useState } from 'react'
 
export default function Contact({ locale }) {
  const t = locale === 'en' ? en : fr
  const [state, setState] = useState({})
  const [status, setStatus] = useState()
 
  function handleChange(e) {
    setState((prev) => ({
      ...prev,
      [e.target.name]: e.target.value,
    }))
  }
 
  async function handleSubmit(e) {
    e.preventDefault()
    try {
      setStatus()
      let res = await fetch('/api/contact', {
        method: 'POST',
        body: JSON.stringify(state),
        headers: {
          'Content-Type': 'application/json',
        },
      })
      setStatus(res.status)
    } catch (e) {
      setStatus(500)
    }
  }
 
  return (
    <div className="max-w-4xl mx-auto">
      <h1 className="text-center">{t.h1}</h1>
      <DottedLine />
      <p className="text-periwinkle mb-2">{t.p1}</p>
      <p className="text-[.98rem] mb-2">
        {t.p2}
        <a
          href="mailto:ESDC.DGIIT.Dojo-Dojo.IITD.ESDC@hrsdc-rhdcc.gc.ca"
          className="ml-1 underline text-[.95rem] text-periwinkle"
        >
          {t.a}
        </a>
      </p>
      <form
        className="flex flex-col gap-3 text-[.9rem] mt-10"
        aria-describedby="required"
        onSubmit={handleSubmit}
      >
        <p id="required" className="text-[.85rem] text-periwinkle">
          {t.imp}
        </p>
        <div className="flex flex-col sm:flex-row gap-2">
          <div className="flex flex-col w-full">
            <label htmlFor="firstName" className="font-bold text-periwinkle">
              {t.fn}
            </label>
            <input
              required
              id="firstName"
              name="firstName"
              className="border-2 rounded py-2 px-3 border-periwinkle"
              onChange={handleChange}
            ></input>
          </div>
          <div className="flex flex-col w-full">
            <label htmlFor="lastName" className="font-bold text-periwinkle">
              {t.ln}
            </label>
            <input
              required
              id="lastName"
              name="lastName"
              className="border-2 rounded py-2 px-3 border-periwinkle"
              onChange={handleChange}
            ></input>
          </div>
        </div>
        <label htmlFor="email" className="font-bold text-periwinkle">
          {t.email}
        </label>
        <input
          type="email"
          required
          id="email"
          name="email"
          className="border-2 rounded border-periwinkle"
          onChange={handleChange}
        ></input>
        <label htmlFor="workLocation" className="font-bold text-periwinkle">
          {t.where}
        </label>
        <select
          required
          id="workLocation"
          name="workLocation"
          className="border-2 rounded border-periwinkle"
          onChange={handleChange}
        >
          <option></option>
          <option value="IITB">{t.iitb}</option>
          <option value="Other - ESDC">{t.otherEsdc}</option>
          <option value="Other - Government of Canada">{t.otherGoc}</option>
          <option value="Other - Outside the Government of Canada">
            {t.otherOutsideGoc}
          </option>
        </select>
 
        <label htmlFor="nextStep" className="font-bold text-periwinkle">
          {t.nextStep}
        </label>
        <select
          required
          id="nextStep"
          name="nextStep"
          className="border-2 rounded border-periwinkle"
          onChange={handleChange}
        >
          <option></option>
          <option value="Meet with a Dojo Member">{t.meet}</option>
          <option value="Get a Presentation">{t.present}</option>
          <option value="Ask some questions">{t.questions}</option>
          <option value="Other">{t.other}</option>
        </select>
        <label htmlFor="tellUs" className="font-bold text-periwinkle">
          {t.tellUs}
        </label>
        <textarea
          type="textarea"
          id="tellUs"
          name="tellUs"
          className="border-2 rounded border-periwinkle"
          onChange={handleChange}
        ></textarea>
 
        <label htmlFor="howFind" className="font-bold text-periwinkle">
          {t.howFindOut}
        </label>
        <textarea
          id="howFind"
          name="howFind"
          className="border-2 rounded border-periwinkle"
          onChange={handleChange}
        ></textarea>
 
        <button className="mt-5 py-2 bg-periwinkle text-white rounded hover:bg-darkPeriwinkle">
          {t.submit}
        </button>
      </form>
      {status && (
        <div
          role="status"
          className={`${
            status === 200 ? 'bg-green-700' : 'bg-red-700'
          } mt-5 rounded text-white text-center font-semi-bold px-3 py-2`}
        >
          {t[status === 200 ? 'emailSent' : 'emailNotSent']}
        </div>
      )}
    </div>
  )
}
 
export async function getStaticProps({ locale }) {
  /* istanbul ignore next */
  const langToggleLink = locale === 'en' ? '/fr/contact' : '/contact'
 
  /* Place-holder Meta Data Props */
  const meta = {
    data_en: {
      title: 'Digital Dojo - Contact',
      desc: 'English',
      author: '',
      keywords: '',
    },
    data_fr: {
      title: 'Dojo Numérique - Contactez Nous',
      desc: 'Français',
      author: '',
      keywords: '',
    },
  }
 
  return {
    props: { locale, langToggleLink, meta },
  }
}