This commit is contained in:
2023-01-13 00:27:12 +01:00
parent 06849fe684
commit 920ad6ffdb
5 changed files with 82 additions and 3 deletions

View File

@ -1,6 +1,7 @@
import React, { useContext, useState } from 'react'
import { Link } from 'react-router-dom';
import { Axios, ResponseT, UserCtx, UserCtxT } from '../context/UserContext';
import CreateQr from '../services/CreateQr';
import Img from './Img';
import './Profil.css';
@ -30,7 +31,14 @@ function Profil()
email: resDog.data.data.email,
name: resDog.data.data.name,
phone: resDog.data.data.phone
});
});
if(resDog.data.data.qr_code === null)
{
// qrcode generieren und in der Datenbank speichern
CreateQr({qr_id: user.qr_id});
}
})
.catch((err) => console.error(err));
}

49
src/services/CreateQr.ts Normal file
View File

@ -0,0 +1,49 @@
import { Axios } from '../context/UserContext';
import React from 'react'
import QRCodeStyling from 'qr-code-styling';
const upload = (file: File): Promise<any> =>
{
let formData = new FormData();
formData.append("file", file);
formData.append("submit", "1");
formData.append("qr", "1");
let uploadRes = Axios.post("upload.php", formData, {
headers:
{
"Content-Type": "multipart/form-data",
}
});
// let a: number = 1+3;
// a++;
return uploadRes;
};
export default function CreateQr({qr_id}:{qr_id: string | undefined})
{
const qrCode = new QRCodeStyling(
{
width: 200,
height: 200,
image:
"",
data: 'https://hope-fly.de/dog/'+ qr_id,
dotsOptions:
{
color: "#000",
type: "square"
},
imageOptions:
{
crossOrigin: "anonymous",
margin: 0
}
});
// upload(qrCode._svg as File);
console.log(qrCode);
}