Advertisement
kfurfles

Untitled

Mar 29th, 2020
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { usePostHttp } from './useHttp'
  2. import { useToasty } from './useSwal'
  3. import { computed, ref, watchEffect } from '@vue/composition-api'
  4. import { requestExtract } from '@/utils/requestStatus'
  5.  
  6. export const useCreateUser = async (id: string) => {
  7.     const {
  8.         data,
  9.         error,
  10.         loading
  11.     } = usePostHttp<{ name: string }>('sessions', { id })
  12.  
  13.  
  14.     const stop = watchEffect(onValidate => {
  15.         const {  response , errorMsg } = requestExtract({ data, error })
  16.        
  17.         if(!loading.value){
  18.             if (response) {
  19.                 console.log(response)
  20.                 useToasty({
  21.                     title: `Olá ${response}`,
  22.                     icon: 'success'
  23.                 })
  24.             } else {
  25.                 useToasty({
  26.                     title: `ONG não encontrada`,
  27.                     icon: 'error'
  28.                 })
  29.                
  30.             }
  31.             stop()
  32.         }
  33.     })
  34.  
  35.     return {
  36.         data,
  37.         loading
  38.     }
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement