localhost geht hop-fly nicht

This commit is contained in:
2022-12-19 22:07:54 +01:00
parent bac04885b0
commit 3657ddf4ae
16 changed files with 301 additions and 28 deletions

View File

@ -15,6 +15,28 @@ export type TUser =
name: string
}
export type DogT =
{
id: number,
qr_id: string,
email: string,
name: string,
phone: string,
qr_code: string,
picture: string
};
export type ResponseT =
{
success: number,
status: number,
message: string,
fields: string,
data: DogT
} | any;
export type UserCtxT =
{
user: TUser | null,
@ -42,20 +64,25 @@ export type UserCtxT =
getUser: () => Promise<void>,
logout: () => void
logout: () => void,
getDog: (str: string | undefined) => Promise<ResponseT>,
dog: ResponseT
}
export const UserCtx = createContext<UserCtxT | null>(null);
export const Axios = axios.create({
// baseURL: 'http://localhost/dog/php-dog/',
baseURL: 'https://hope-fly.de/dog/php-dog/',
baseURL: 'http://localhost/dog/php-dog/',
// baseURL: 'https://hope-fly.de/dog/php-dog/',
});
export const UserCtxProvider = ({children}:TUserContextProviderProps) => {
const [user, setUser] = useState<TUser | null>(null);
const [wait, setWait] = useState(false);
const [dog, setDog] = useState<ResponseT>({});
const registerUser = async ({email,password}:
{email: string, password: string}) => {
@ -154,6 +181,29 @@ export const UserCtxProvider = ({children}:TUserContextProviderProps) => {
setUser(null);
}
const getDog = async ( str: string | undefined) =>
{
var ret: ResponseT = {};
setWait(true);
try
{
ret = await Axios.post<ResponseT>('getDog.php',
{
qr_id: str
});
setDog(ret.data as ResponseT);
setWait(false);
return;
}
catch (error:any)
{
console.log('error message: ', error.message);
setWait(false);
return;
}
};
return (
<UserCtx.Provider value={
{
@ -162,7 +212,9 @@ export const UserCtxProvider = ({children}:TUserContextProviderProps) => {
wait,
user,
getUser,
logout
logout,
getDog,
dog
}}
>
{children}