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AAKT,aAAanB,IAAIe,EAC/B,EAKA,gBAAIqB,CAAaA,GACfR,KAAKT,aAAaI,IAAIR,EAAmBqB,EAC3C,EAEJ,C","sources":["webpack://stdcheck-exposed-wp-theme/./themes/stdcheck-exposed/src/js/components/get-free-university.js","webpack://stdcheck-exposed-wp-theme/./themes/stdcheck-exposed/src/js/services/http.js","webpack://stdcheck-exposed-wp-theme/./themes/stdcheck-exposed/src/js/services/storage.js"],"sourcesContent":["import { HttpService } from '../services/http';\nimport { StorageService } from '../services/storage';\n\nexport function GetFreeUniversityComponent() {\n  const httpService = new HttpService();\n  const storageService = new StorageService();\n  const errorContainer = document.querySelector('#free-university-error-container');\n  const emailInput = document.querySelector('#free-university-email');\n  const submitButton = document.querySelector('#free-university-submit');\n\n  /**\n   * Initialize the component\n   */\n  window.addEventListener('load', () => {\n    emailEvents();\n    submitButton.addEventListener('click', () => onSubmit());\n  });\n\n  /**\n   * Creates the event's listener for the email input\n   */\n  function emailEvents() {\n    emailInput.addEventListener('blur', () => emailRequiredValidation());\n    emailInput.addEventListener('keyup', () => emailRequiredValidation());\n  }\n\n  /**\n   * Perform the email required validation\n   */\n  function emailRequiredValidation() {\n    if (!emailInput.value) {\n      toggleError(true, 'Email is required.');\n\n      return false;\n    }\n\n    toggleError(false);\n\n    return true;\n  }\n\n  /**\n   * Toggle the error message\n   *\n   * @param show True to show the error message, false to hide it\n   * @param errorMessage The error message to display\n   */\n  function toggleError(show, errorMessage) {\n    if (!show) {\n      errorContainer.classList.add('is-hidden');\n\n      return;\n    }\n\n    errorContainer.children[0].innerHTML = `<span> <i class=\"fa fa-exclamation-triangle\"></i> ${errorMessage}</span>`;\n    errorContainer.classList.remove('is-hidden');\n  }\n\n  /**\n   * Submits the form\n   */\n  function onSubmit() {\n    event.preventDefault();\n\n    if (!onSubmitValidations()) {\n      return;\n    }\n\n    toggleError(false);\n    const startedRequest = {\n      email: emailInput.value,\n      universities_id: emailInput.getAttribute('data-university-id'),\n    };\n\n    httpService\n      .post(`${process.env.API_URL}/order-free-test`, startedRequest)\n      .then((response) => handleValidResponse(response))\n      .catch((error) => handleInvalidResponse(error));\n  }\n\n  /**\n   * Perform the validations before submit the form\n   */\n  function onSubmitValidations() {\n    if (!emailRequiredValidation()) {\n      return false;\n    }\n\n    if (!emailInput.checkValidity()) {\n      toggleError(true, 'Email is invalid.');\n\n      return false;\n    }\n\n    return true;\n  }\n\n  /**\n   * Handles an invalid response from the server\n   *\n   * @param response The response from the server\n   */\n  function handleInvalidResponse(response) {\n    let errorResponse = 'There was an error. Please try again or contact us.';\n\n    if (response.code === 417) {\n      errorResponse = 'Please enter your school email address.';\n    }\n\n    toggleError(true, errorResponse);\n  }\n\n  /**\n   * Handles a valid response from the server\n   *\n   * @param response The response from the server\n   */\n  function handleValidResponse(response) {\n    storageService.tests = response.tests;\n    storageService.email = response.email;\n    storageService.free = response.free;\n    window.location.href = '/order';\n  }\n}\n\nwindow.changeLocation = new GetFreeUniversityComponent();\n","/**\n * Service class for making HTTP requests\n */\nexport function HttpService() {\n  /**\n   * Make an HTTP request that expects a JSON response\n   *\n   * @param {*} url       The URL to make the request to\n   * @param {*} options   options for the fetch function\n   *\n   * @returns {Promise}   A promise that resolves with the JSON response data, or rejects for any of these reasons:\n   *                      1. The HTTP status code is not between 200-299\n   *                      2. The response is not valid JSON\n   *                      3. Network failures or anything that prevented the HTTP request from completing\n   */\n  function fetchJson(url, options = {}) {\n    options.headers = { Accept: 'application/json', 'Content-Type': 'application/json' };\n\n    return new Promise((resolve, reject) => {\n      fetch(url, options)\n        .then((response) => {\n          if (response.ok && response.status !== 204) {\n            response.json().then((data) => resolve(data));\n          } else if (response.ok && response.status === 204) {\n            resolve();\n          } else {\n            response.json().then((errorResponse) => {\n              errorResponse.code = response.status;\n              reject(errorResponse);\n            });\n          }\n        })\n        .catch((error) => reject(error));\n    });\n  }\n\n  return {\n    /**\n     * Make a GET request to the specified URL\n     *\n     * @param {string} url  The URL to make the request to\n     *\n     * @returns {Promise} A Promise that resolves with the response data when successful, and rejects on failure\n     */\n    get: (url) => fetchJson(url, { method: 'GET' }),\n\n    /**\n     * Make a POST request to the specified URL\n     *\n     * @param {string} url  The URL to make the request to\n     * @param {any} body    The request body\n     *\n     * @returns {Promise} A Promise that resolves with the response data when successful, and rejects on failure\n     */\n    post: (url, body) => fetchJson(url, { method: 'POST', body: JSON.stringify(body) }),\n  };\n}\n","/**\n * Service class for accessing localStorage.\n */\nexport function StorageService() {\n  /**\n   * Keys used to reference data in localStorage\n   */\n  const CJ_EVENT_KEY = 'ngStorage-cjevent';\n  const COUPON_KEY = 'ngStorage-coupon';\n  const FEE_KEY = 'ngStorage-fee';\n  const LAB_KEY = 'ngStorage-center';\n  const REORDER_KEY = 'ngStorage-reorder';\n  const TESTS_KEY = 'ngStorage-tests';\n  const TOKEN_KEY = 'ngStorage-token';\n  const ZIPCODE_KEY = 'ngStorage-zip_code';\n  const IN_HOME_KEY = 'ngStorage-in-home-booking-result';\n  const EMAIL_KEY = 'ngStorage-email';\n  const FREE_KEY = 'ngStorage-free';\n  const TRANSACTION_ID_KEY = 'transaction_id';\n  const BETTER_LAB = 'ngStorage-betterlab';\n  const IHC_PROVIDERS_KEY = 'ngStorage-ihc-providers';\n\n  /**\n   * Retrieves a value stored as JSON in localStorage\n   *\n   * @param {string} key the key to retrieve from storage\n   *\n   * @return {any}  The value stored in localStorage\n   */\n  function getLocalStorage(key) {\n    return JSON.parse(window.localStorage?.getItem(key) || null);\n  }\n\n  /**\n   * Saves a value in localStorage as a JSON string\n   *\n   * @param {string} key The key to store the value in\n   * @param {any} value  The value to be stored\n   *\n   * @return {void}\n   */\n  function setLocalStorage(key, value) {\n    window.localStorage?.setItem(key, JSON.stringify(value || null));\n  }\n\n  /**\n   * Deletes a value from the storage.\n   *\n   * @param key {string} The value's key.\n   *\n   * @return void\n   */\n  function removeLocalStorage(key) {\n    window.localStorage?.removeItem(key);\n  }\n\n  // Initialize tests in localStorage\n  if (!getLocalStorage(TESTS_KEY)) {\n    setLocalStorage(TESTS_KEY, []);\n  }\n\n  return {\n    /**\n     * Local Storage get, set and remove\n     */\n    localStorage: {\n      get: getLocalStorage,\n      set: setLocalStorage,\n      remove: removeLocalStorage,\n    },\n\n    /**\n     * Removes any reorder information from local storage\n     */\n    removeReorderInformation: function () {\n      window.localStorage?.removeItem(REORDER_KEY);\n    },\n\n    /**\n     * Removes previous order information from local storage\n     */\n    removePreviousOrderInformation: function () {\n      window.localStorage?.removeItem(TRANSACTION_ID_KEY);\n      window.localStorage?.removeItem(BETTER_LAB);\n    },\n\n    /**\n     * Retrieve coupon data from local storage\n     */\n    get coupon() {\n      return this.localStorage.get(COUPON_KEY) ?? {};\n    },\n\n    /**\n     * Store coupon data in local storage\n     */\n    set coupon(coupon) {\n      this.localStorage.set(COUPON_KEY, coupon);\n    },\n\n    /**\n     * Retrieve fee data from localStorage\n     */\n    get fee() {\n      return this.localStorage.get(FEE_KEY);\n    },\n\n    /**\n     * Store fee data in localStorage\n     */\n    set fee(fee) {\n      this.localStorage.set(FEE_KEY, fee);\n    },\n\n    /**\n     * Retrieve lab data from local storage\n     */\n    get lab() {\n      return this.localStorage.get(LAB_KEY) ?? {};\n    },\n\n    /**\n     * Store lab data in local storage\n     */\n    set lab(lab) {\n      this.localStorage.set(LAB_KEY, lab);\n    },\n\n    /**\n     * Retrieve psc data from local storage\n     */\n    get psc() {\n      return this.lab;\n    },\n\n    /**\n     * Store psc data in local storage\n     */\n    set psc(psc) {\n      this.lab = psc;\n    },\n\n    /**\n     * Retrieve selected tests data from local storage\n     */\n    get tests() {\n      return this.localStorage.get(TESTS_KEY) ?? [];\n    },\n\n    /**\n     * Store selected tests data in local storage\n     */\n    set tests(tests) {\n      this.localStorage.set(TESTS_KEY, tests);\n    },\n\n    /**\n     * Retrieve token data from localStorage\n     */\n    get token() {\n      return this.localStorage.get(TOKEN_KEY);\n    },\n\n    /**\n     * Store token data in localStorage\n     */\n    set token(token) {\n      this.localStorage.set(TOKEN_KEY, token);\n    },\n\n    /**\n     * Retrieve CJ Affiliate data from localStorage\n     */\n    get cjevent() {\n      return this.localStorage.get(CJ_EVENT_KEY);\n    },\n\n    /**\n     * Store CJ Affiliate data in localStorage\n     */\n    set cjevent(cjevent) {\n      this.localStorage.set(CJ_EVENT_KEY, cjevent);\n    },\n\n    /**\n     * Retrieve zip code data from localStorage\n     */\n    get zipCode() {\n      return this.localStorage.get(ZIPCODE_KEY);\n    },\n\n    /**\n     * Store zip code data in localStorage\n     */\n    set zipCode(zipCode) {\n      this.localStorage.set(ZIPCODE_KEY, zipCode);\n    },\n\n    get inHomeResult() {\n      return this.localStorage.get(IN_HOME_KEY);\n    },\n\n    /**\n     * Retrieve email data from local storage\n     */\n    get email() {\n      return this.localStorage.get(EMAIL_KEY) ?? {};\n    },\n\n    /**\n     * Store email data in local storage\n     */\n    set email(email) {\n      this.localStorage.set(EMAIL_KEY, email);\n    },\n\n    /**\n     * Retrieve free order data from local storage\n     */\n    get free() {\n      return this.localStorage.get(FREE_KEY) ?? {};\n    },\n\n    /**\n     * Store free order data in local storage\n     */\n    set free(free) {\n      this.localStorage.set(FREE_KEY, free);\n    },\n\n    /**\n     * Retrieve In-Home Collection provider IDs from local storage\n     */\n    get ihcProviders() {\n      return this.localStorage.get(IHC_PROVIDERS_KEY);\n    },\n\n    /**\n     * Store In-Home Collection provider IDs in local storage\n     */\n    set ihcProviders(ihcProviders) {\n      this.localStorage.set(IHC_PROVIDERS_KEY, ihcProviders);\n    },\n  };\n}\n"],"names":["window","changeLocation","httpService","storageService","errorContainer","document","querySelector","emailInput","submitButton","emailRequiredValidation","value","toggleError","show","errorMessage","children","innerHTML","classList","remove","add","addEventListener","event","preventDefault","checkValidity","startedRequest","email","universities_id","getAttribute","post","then","response","tests","free","location","href","handleValidResponse","catch","error","errorResponse","code","handleInvalidResponse","onSubmit","HttpService","fetchJson","url","options","headers","Accept","Promise","resolve","reject","fetch","ok","status","json","data","get","method","body","JSON","stringify","StorageService","CJ_EVENT_KEY","COUPON_KEY","FEE_KEY","LAB_KEY","TESTS_KEY","TOKEN_KEY","ZIPCODE_KEY","EMAIL_KEY","FREE_KEY","IHC_PROVIDERS_KEY","getLocalStorage","key","parse","localStorage","getItem","setLocalStorage","setItem","set","removeItem","removeReorderInformation","removePreviousOrderInformation","coupon","this","fee","lab","psc","token","cjevent","zipCode","inHomeResult","ihcProviders"],"sourceRoot":""}