Skip to content

Commit

Permalink
Contact section
Browse files Browse the repository at this point in the history
  • Loading branch information
RemOclock committed Sep 7, 2023
1 parent 6d96b37 commit 86830b1
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
VITE_APP_EMAILJS_SERVICE_ID=
VITE_APP_EMAILJS_TEMPLATE_ID=
VITE_APP_EMAILJS_PUBLIC_KEY=
10 changes: 10 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"react-router-dom": "^6.8.1",
"react-tilt": "^0.1.4",
"react-vertical-timeline-component": "^3.6.0",
"sweetalert2": "^11.7.27",
"three": "^0.149.0"
},
"devDependencies": {
Expand All @@ -30,4 +31,4 @@
"tailwindcss": "^3.2.6",
"vite": "^4.1.0"
}
}
}
39 changes: 32 additions & 7 deletions src/components/Contact.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useRef, useState } from "react";
import { motion } from "framer-motion";
import emailjs from "@emailjs/browser";
import Swal from 'sweetalert2'

import { styles } from "../styles";
import { EarthCanvas } from "./canvas";
Expand Down Expand Up @@ -31,23 +32,41 @@ const Contact = () => {
e.preventDefault();
setLoading(true);

if (typeof name === 'undefined' || typeof email === 'undefined' || typeof message === 'undefined') {
Swal.fire({
position: 'top-end',
icon: 'error',
title: 'Please fill all the fields ! 😁',
showConfirmButton: false,
timer: 3000
});
setLoading(false);
return;
}

emailjs
.send(
import.meta.env.VITE_APP_EMAILJS_SERVICE_ID,
import.meta.env.VITE_APP_EMAILJS_TEMPLATE_ID,
{
from_name: form.name,
to_name: "JavaScript Mastery",
to_name: "Rémi Sulpice | RTekk",
from_email: form.email,
to_email: "[email protected]",
to_email: "[email protected]",
message: form.message,
},
import.meta.env.VITE_APP_EMAILJS_PUBLIC_KEY
)
.then(
() => {
setLoading(false);
alert("Thank you. I will get back to you as soon as possible.");
Swal.fire({
position: 'top-end',
icon: 'success',
title: 'Thank you. I will get back to you as soon as possible ! 🫡',
showConfirmButton: false,
timer: 3000
});

setForm({
name: "",
Expand All @@ -59,7 +78,13 @@ const Contact = () => {
setLoading(false);
console.error(error);

alert("Ahh, something went wrong. Please try again.");
Swal.fire({
position: 'top-end',
icon: 'error',
title: 'Ahh, something went wrong. Please try again ! 🥲',
showConfirmButton: false,
timer: 3000
});
}
);
};
Expand Down Expand Up @@ -87,7 +112,7 @@ const Contact = () => {
name='name'
value={form.name}
onChange={handleChange}
placeholder="What's your good name?"
placeholder="Thomas Anderson"
className='bg-tertiary py-4 px-6 placeholder:text-secondary text-white rounded-lg outline-none border-none font-medium'
/>
</label>
Expand All @@ -98,7 +123,7 @@ const Contact = () => {
name='email'
value={form.email}
onChange={handleChange}
placeholder="What's your web address?"
placeholder="[email protected]"
className='bg-tertiary py-4 px-6 placeholder:text-secondary text-white rounded-lg outline-none border-none font-medium'
/>
</label>
Expand All @@ -109,7 +134,7 @@ const Contact = () => {
name='message'
value={form.message}
onChange={handleChange}
placeholder='What you want to say?'
placeholder='Follow the white rabbit...'
className='bg-tertiary py-4 px-6 placeholder:text-secondary text-white rounded-lg outline-none border-none font-medium'
/>
</label>
Expand Down

0 comments on commit 86830b1

Please sign in to comment.