From 6939273d6bbb93dc6c99a5229e142ecfd4dd2b5f Mon Sep 17 00:00:00 2001 From: Peter Hoppe Date: Mon, 6 Feb 2023 16:41:34 +0100 Subject: [PATCH] contact email --- src/components/Dog.tsx | 2 +- src/components/DogContactForm.tsx | 85 +++++++++++++++++++++++++++++++ src/components/DogNameTxt.tsx | 22 ++++++-- src/components/dog.code-workspace | 11 ---- src/dog.code-workspace | 11 ++++ src/services/PhpApi.ts | 25 +++++++++ tsconfig.json | 1 + 7 files changed, 140 insertions(+), 17 deletions(-) create mode 100644 src/components/DogContactForm.tsx delete mode 100644 src/components/dog.code-workspace create mode 100644 src/dog.code-workspace diff --git a/src/components/Dog.tsx b/src/components/Dog.tsx index 96164b7..fa1b586 100644 --- a/src/components/Dog.tsx +++ b/src/components/Dog.tsx @@ -45,7 +45,7 @@ const Dog = () =>

pic: {picPath}

qr: {qrPath}

*/} - + : <>; diff --git a/src/components/DogContactForm.tsx b/src/components/DogContactForm.tsx new file mode 100644 index 0000000..9531494 --- /dev/null +++ b/src/components/DogContactForm.tsx @@ -0,0 +1,85 @@ +import { useState } from "react"; +import toast, { Toaster } from "react-hot-toast"; +import { foundMsg, logFormData } from "../services/PhpApi"; + + +export default function DogContactForm( + {toEmail, name, qr_id}: + {toEmail: string, name: string, qr_id: string}) +{ + const formdata_init = new FormData(); + formdata_init.append('fromEmail', ''); + formdata_init.append('msg', ''); + const [formData, setFormData] = useState(formdata_init); + + const onChangeInput = (e: React.FormEvent ) => + { + setFormData({ + ...formData, + [e.currentTarget.name]:e.currentTarget.value + }) + + + } + + const submitForm = async (e: React.FormEvent) => + { + e.preventDefault(); + + if(!Object.values(formData).every(val => val.trim() !== '')) + { + toast.error('Bitte alle Felder ausfüllen!'); + return; + } + +// const sendData: any = {...formData}; + const sendData = new FormData(); + const values = Object.values(formData); + const keys = Object.keys(formData); + + for (const key of keys) + { + const index = keys.indexOf(key); + sendData.append(key, values[index]); + + console.log(key + ' ' + sendData.get(key)); + } + + sendData.append('toEmail', toEmail); + sendData.append('name', name); + sendData.append('qr_id', qr_id); + + logFormData(sendData); + + const data = await foundMsg(sendData); +// const data = { +// success:0, +// message: 'yyy' +// }; + + if(data.success) + { + toast.success('Nachricht gesendet!'); + } + else if(!data.success && data.message) + { + toast.error(data.message); + } + } + + return ( +
+ +
+ + +
+
+ + +
+ + +); + +} \ No newline at end of file diff --git a/src/components/DogNameTxt.tsx b/src/components/DogNameTxt.tsx index e4ca154..74ae6be 100644 --- a/src/components/DogNameTxt.tsx +++ b/src/components/DogNameTxt.tsx @@ -1,13 +1,25 @@ import React from 'react' +import DogContactForm from './DogContactForm' export default function DogNameTxt( - {name, email, phone}: - {name: string, email: string, phone: string}) { + {name, email, phone, qr_id}: + {name: string, email: string, phone: string, qr_id: string}) { return (
-

Hallo ich bin

{name}!

-

bitte schreib eine Mail an

{email}

- oder ruf
{phone}
an,
damit ich schnell wieder Heim komme.

+

Hallo ich bin +

{name}!

+

+ +

+ schreib eine Mail an +

{email}

+ oder ruf +
+
{phone}
+ an, +
+ damit ich schnell wieder Heim komme. +

) } diff --git a/src/components/dog.code-workspace b/src/components/dog.code-workspace deleted file mode 100644 index 5f503bb..0000000 --- a/src/components/dog.code-workspace +++ /dev/null @@ -1,11 +0,0 @@ -{ - "folders": [ - { - "path": "../.." - }, - { - "path": "../../../../../../../../../opt/lampp/htdocs/dog/php-dog" - } - ], - "settings": {} -} \ No newline at end of file diff --git a/src/dog.code-workspace b/src/dog.code-workspace new file mode 100644 index 0000000..760b1cf --- /dev/null +++ b/src/dog.code-workspace @@ -0,0 +1,11 @@ +{ + "folders": [ + { + "path": ".." + }, + { + "path": "../../../../../../../../opt/lampp/htdocs/dog/php-dog" + } + ], + "settings": {} +} \ No newline at end of file diff --git a/src/services/PhpApi.ts b/src/services/PhpApi.ts index 6390b59..7cc1b7f 100644 --- a/src/services/PhpApi.ts +++ b/src/services/PhpApi.ts @@ -85,6 +85,31 @@ export const registerUser = async ({email,password}: } } +export function logFormData(form_data: FormData) +{ + for (const key of form_data.keys()) + { + console.log(key + ' ' + form_data.get(key)); + + } +} + +export const foundMsg = async (form_data: + FormData) => +{ + try + { + const {data} = await Axios.post('foundEmail.php', form_data); + console.log('Api foundMsg'); + console.log(data); + return data; + } + catch(err) + { + return {success:0, message:'Server Error!'}; + } +} + 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}) => { diff --git a/tsconfig.json b/tsconfig.json index a273b0c..0a1b50a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,6 +6,7 @@ "dom.iterable", "esnext" ], + "downlevelIteration": true, "allowJs": true, "skipLibCheck": true, "esModuleInterop": true,