Skip to content
Snippets Groups Projects
customPopup.service.ts 1.03 KiB
Newer Older
  • Learn to ignore specific revisions
  • Bastien DUMONT's avatar
    Bastien DUMONT committed
    import axios, { AxiosRequestConfig } from 'axios'
    import { toast } from 'react-toastify'
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    import { ICustomPopup } from '../models/customPopup.model'
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    
    export class CustomPopupService {
      /**
       * Save the customPopup info
       * @param customPopup
       * @param axiosHeaders
       */
      public saveCustomPopup = async (
        customPopup: ICustomPopup,
        axiosHeaders: AxiosRequestConfig
      ): Promise<void> => {
        try {
          await axios.put(
    
            `/api/animator/customPopup`,
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
            {
              ...customPopup,
            },
            axiosHeaders
          )
          toast.success('Pop-up personnalisée enregistrée !')
        } catch (e) {
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
          toast.error('Erreur lors de l’enregistrement de la pop-up personnalisée')
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
          console.error(e)
        }
      }
    
      /**
       * Gets the custom pop-up information
       */
      public getCustomPopupInfo = async (): Promise<ICustomPopup | null> => {
        try {
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
          const { data } = await axios.get<ICustomPopup>(`/api/common/customPopup`)
          return data
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        } catch (e) {
          console.error('error', e)
          return null
        }
      }
    }