Compare commits

..
3 Commits
Author SHA1 Message Date
auto f52201b683 Rename variables for clarity and adjust download filename and contents
Renamed the parameter 'e' to 'formikValues' for better clarity in the handleSubmit function. Now load formikValues into the file that get's uploaded so it has the up to date form data. Changed the downloaded JSON filename from 'form_data.json' to 'your_form_data.json' to be more user-friendly.
2024-08-06 23:21:53 +02:00
auto 9a281ed76c Update backend URLs to use environment variables
Replaced hardcoded backend URLs with environment variables in contact, apply, and verify_email components. Added .env.development and .env.production files to define the base URLs for different environments. This improves flexibility and allows easier configuration changes.
2024-08-06 23:17:37 +02:00
auto 997baae4d3 Fix JSON serialization in error handling
Replaced steps variable with userInput for JSON serialization in error handling. This ensures that the correct data is saved as a JSON blob when a network error occurs.
2024-08-06 22:28:41 +02:00
6 changed files with 10 additions and 8 deletions
+1
View File
@@ -0,0 +1 @@
REACT_APP_BACKEND_BASE_URL=http://localhost:8002
+1
View File
@@ -0,0 +1 @@
REACT_APP_BACKEND_BASE_URL=https://forms-backend.alttd.com
+1 -1
View File
@@ -124,7 +124,7 @@ export const apply: FormData = {
required: false, required: false,
}, },
], ],
backend: 'https://forms-backend.alttd.com/api/apply/staffApplication', backend: `${process.env.REACT_APP_BACKEND_BASE_URL}/api/apply/staffApplication`,
userInput: {username: '', email: '', discord: '', pc_requirements: '' userInput: {username: '', email: '', discord: '', pc_requirements: ''
, age: '', pronoun: '', join_date: '', avg_time: '', available_days: '', available_time: '', staff_experience: '' , age: '', pronoun: '', join_date: '', avg_time: '', available_days: '', available_time: '', staff_experience: ''
, plugin_experience: '', why_staff: '', expectations_mod: '', other: '' , plugin_experience: '', why_staff: '', expectations_mod: '', other: ''
+1 -1
View File
@@ -28,7 +28,7 @@ export const contact: FormData = {
required: true, required: true,
}, },
], ],
backend: 'https://forms-backend.alttd.com/api/contact/submitContactForm', backend: `${process.env.REACT_APP_BACKEND_BASE_URL}/api/contact/submitContactForm`,
userInput: {username: '', email: '', question: ''}, userInput: {username: '', email: '', question: ''},
spec: Yup.object().shape({ spec: Yup.object().shape({
username: Yup.string() username: Yup.string()
+5 -5
View File
@@ -15,23 +15,23 @@ const GenericForm = (formData: FormData) => {
const [currentStep, setCurrentStep] = useState<number>(0); const [currentStep, setCurrentStep] = useState<number>(0);
const handleSubmit = async (e: FormikValues) => { const handleSubmit = async (formikValues: FormikValues) => {
try { try {
const response = await fetch(backend, { const response = await fetch(backend, {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
}, },
body: JSON.stringify(e) body: JSON.stringify(formikValues)
}) })
if (!response.ok) { if (!response.ok) {
let json: string = JSON.stringify(steps); let json: string = JSON.stringify(formikValues);
const blob = new Blob([json], {type: "application/json"}); const blob = new Blob([json], {type: "application/json"});
const url = URL.createObjectURL(blob); const url = URL.createObjectURL(blob);
const link = document.createElement('a'); const link = document.createElement('a');
link.href = url; link.href = url;
link.download = 'form_data.json'; link.download = 'your_form_data.json';
link.click(); link.click();
URL.revokeObjectURL(url); URL.revokeObjectURL(url);
//TODO clean up //TODO clean up
@@ -39,7 +39,7 @@ const GenericForm = (formData: FormData) => {
} else { } else {
navigate('/verify-email', { navigate('/verify-email', {
state: { state: {
email: e['email'] email: formikValues['email']
} }
}); });
} }
+1 -1
View File
@@ -42,7 +42,7 @@ const VerifyMail: FC = () => {
eMail: email eMail: email
} }
console.log(verificationData); console.log(verificationData);
fetch('https://forms-backend.alttd.com/api/verify_email/form', { fetch(`${process.env.REACT_APP_BACKEND_BASE_URL}/api/verify_email/form`, {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',