This commit is contained in:
2023-01-30 00:02:26 +01:00
parent 752e6c491a
commit ff8e4bc831
11 changed files with 204 additions and 284 deletions

View File

@ -1,5 +1,4 @@
import {UserCtx, UserCtxT, ResponseT, TUser} from '../context/UserContext';
import React, {useContext} from 'react';
import {ResponseT, TUser} from '../context/UserContext';
import axios from 'axios'
export const Axios = axios.create({
@ -12,19 +11,15 @@ export const Axios = axios.create({
export const updateDog = async ({email, name, phone}:
{email: string, name: string, phone: string}) =>
{
// const { setWait } = useContext<UserCtxT | null>(UserCtx) as UserCtxT;
// setWait(true);
try{
const {data} = await Axios.post('updateDog.php',{
email,
name,
phone
});
// setWait(false);
return data;
}
catch(err){
// setWait(false);
return {success:0, message:'Server Error!'};
}
}
@ -32,7 +27,6 @@ export const updateDog = async ({email, name, phone}:
export const getDog = async ( str: string | undefined) : Promise<ResponseT> =>
{
var ret: ResponseT = {};
// setWait(true);
try
{
@ -40,14 +34,11 @@ export const getDog = async ( str: string | undefined) : Promise<ResponseT> =>
{
qr_id: str
});
// setDog(ret.data as ResponseT);
// setWait(false);
return ret.data as ResponseT;
}
catch (error:any)
{
console.log('error message: ', error.message);
// setWait(false);
ret =
{
success: 0,
@ -63,20 +54,16 @@ export const getDog = async ( str: string | undefined) : Promise<ResponseT> =>
export const registerUser = async ({email,password}:
{email: string, password: string}) =>
{
// const { setWait } = useContext<UserCtxT | null>(UserCtx) as UserCtxT;
// setWait(true);
try{
const {data} = await Axios.post('register.php',
{
email,
password
});
// setWait(false);
return data;
}
catch(err)
{
// setWait(false);
return {success:0, message:'Server Error!'};
}
}
@ -84,9 +71,6 @@ export const registerUser = async ({email,password}:
export const updateQR = async ({qr_width_cm, qr_height_cm, qr_fontsize, qr_visible_items, qr_item_sequence}:
{qr_width_cm: number, qr_height_cm: number, qr_fontsize: number, qr_visible_items: number, qr_item_sequence: number}) =>
{
// const { setWait } = useContext<UserCtxT | null>(UserCtx) as UserCtxT;
// setWait(true);
try
{
const {data} = await Axios.post('updateQR.php',
@ -97,20 +81,16 @@ export const updateQR = async ({qr_width_cm, qr_height_cm, qr_fontsize, qr_visib
qr_visible_items,
qr_item_sequence
});
// setWait(false);
return data;
}
catch(err)
{
// setWait(false);
return {success:0, message:'Server Error!'};
}
}
export const loginUser = async ({email,password}:{email: string, password: string}) =>
{
// const { setWait } = useContext<UserCtxT | null>(UserCtx) as UserCtxT;
// setWait(true);
try
{
var postReturn:
@ -133,23 +113,41 @@ export const loginUser = async ({email,password}:{email: string, password: strin
const {data} = postReturn;
if(data.success && data.data)
{
// setUser(data.data);
// setWait(false);
return {success:1};
}
// setWait(false);
return {success:0, message:data.message};
}
catch(err)
{
// setWait(false);
return {success:0, message:'Server Error!'};
}
}
// export const logout = async () =>
// {
// await Axios.get('logout.php');
// }
export const getProfilData = async () =>
{
const profilData = await Axios.post('getProfilData.php');
const {data} = profilData;
if(data.success && data.user)
{
return data;
}
else
{
return null;
}
}
export const getUser = async () =>
{
const {data} = await Axios.get('getUser.php');
if(data.success && data.user)
{
return data;
}
else
{
return null;
}
}