9 Commits
Author SHA1 Message Date
auto afb833bd19 Add useCallback to optimize handleCheckForm
Refactored handleCheckForm using useCallback to prevent unnecessary re-renders. This ensures the function is only re-created when formData.backendFormName changes, improving performance. Updated useEffect dependencies to include handleCheckForm for proper effect cleanup.
2024-08-10 03:27:28 +02:00
auto 6215944972 Fix missing promise handling in formActiveRedirect
Added a then() clause to handle the resolved promise after calling handleCheckForm in the useEffect. This ensures any asynchronous operations complete as expected and avoids potential unhandled promise rejections.
2024-08-10 03:24:46 +02:00
auto a08c55ec41 Remove GenericForm import from App.tsx
GenericForm was imported but never used in App.tsx. This clean-up helps in maintaining the codebase by removing unnecessary imports, thus enhancing readability and reducing potential confusion.
2024-08-10 03:24:07 +02:00
auto 2a56144bbc Enhance npm cache clean error handling in Jenkinsfile
Wrapped npm cache clean command in a try-catch block to improve error handling. This ensures that the build process can proceed even if the npm cache clean step fails. Added an informational echo message for better diagnostics in case of failure.
2024-08-10 03:21:16 +02:00
auto 98b86363f5 Add npm install fallback and remove unused variable
Added a fallback npm install command in the Jenkinsfile to handle legacy peer dependencies. Also removed an unused variable from genericForm.tsx to improve code clarity and performance.
2024-08-10 03:19:26 +02:00
auto 75559af7c8 Add form active status check and redirection
Introduced `FormActiveRedirect` component to check if forms are active before rendering. Updated form data to include `backendFormName` and adjusted routes in `App.tsx` to use the new component. This ensures that inactive forms redirect users with a relevant message.
2024-08-10 03:10:25 +02:00
auto 21e23b98ad Remove unused Field import from GenericForm
This commit eliminates the unused Field import from Formik in the genericForm.tsx file. Removing unused imports helps maintain cleaner and more efficient code.
2024-08-10 00:27:24 +02:00
auto 67eddc0394 Merge branch 'refs/heads/dev' 2024-08-10 00:26:46 +02:00
auto 960fc1707b Refactor conditional stage in Jenkinsfile
Updated the 'discord' stage condition to use 'anyOf' for more readable and maintainable branch checks. This change enhances the clarity of branch conditions, ensuring it triggers on either the 'main' or 'master' branches.
2024-08-08 20:38:05 +02:00
7 changed files with 60 additions and 9 deletions
Vendored
+12
View File
@@ -11,7 +11,11 @@ pipeline {
def success = false
// Clean npm cache and try normal install and npm ci once
try {
sh 'npm cache clean --force'
} catch (Exception e0) {
echo 'npm cache clean --force failed trying more things'
}
try {
sh 'npm install'
success = true
@@ -39,6 +43,12 @@ pipeline {
echo "Retry ${retryCount}/${MAX_RETRIES} failed"
}
}
try {
sh 'npm install --legacy-peer-deps --force'
success = true
} catch (Exception e4) {
echo "npm install --legacy-peer-deps --force failed"
}
}
if (!success) {
@@ -56,9 +66,11 @@ pipeline {
}
stage('discord') {
when {
anyOf {
branch 'main'
branch 'master'
}
}
steps {
discordSend description: "Build: ${BUILD_NUMBER}", showChangeset: true, result: currentBuild.currentResult, title: currentBuild.fullProjectName, webhookURL: env.discordwebhook
}
+2 -2
View File
@@ -6,9 +6,9 @@ import Footer from "./components/footer/footer";
import VerifyMail from "./components/verify_email/verify_mail";
import ThankYou from "./components/verify_email/thank_you";
import DEBUG from "./components/DEBUG/DEBUG";
import GenericForm from "./components/form/genericForm";
import {getFormProperties} from "./components/form/formData";
import {FormProperties} from "./components/form/formInterfaces";
import FormActiveRedirect from "./components/form/formActiveRedirect";
function App() {
return (
@@ -21,7 +21,7 @@ function App() {
<Route
key={property.path}
path={property.path}
element={<GenericForm {...property.formData} />}
element={<FormActiveRedirect {...property.formData} />}
/>
))}
<Route path="/verify-email" element={<VerifyMail/>}/>
+2 -1
View File
@@ -213,5 +213,6 @@ export const apply: FormData = {
other: Yup.string()
.max(2000, 'Please provide at most 2000 characters')
}),
title: "Staff Application"
title: "Staff Application",
backendFormName: "StaffApplication",
};
+2 -1
View File
@@ -48,5 +48,6 @@ export const contact: FormData = {
.max(2000, 'Question should not exceed 2000 characters')
.required('Question is required')
}),
title: "Contact Form"
title: "Contact Form",
backendFormName: "ContactForm",
};
@@ -0,0 +1,37 @@
import {FormData} from "./formInterfaces";
import {useEffect, useState, useCallback} from "react";
import GenericForm from "./genericForm";
const FormActiveRedirect = (formData: FormData) => {
const [isLoading, setLoading] = useState(true);
const [isFormActive, setFormActive] = useState(false);
const handleCheckForm = useCallback(async () => {
const result = await fetch(`${process.env.REACT_APP_BACKEND_BASE_URL}/api/checks/formActive`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ formName: formData.backendFormName })
});
const response = await result.json();
setFormActive(response.isActive);
setLoading(false);
}, [formData.backendFormName]);
useEffect(() => {
handleCheckForm().then(() => {});
}, [handleCheckForm]);
if (isLoading) {
return <div className={"container"}><h2>Checking if form is active</h2></div>;
}
if (!isFormActive) {
return <div className={"container"}><h2>The {formData.title} is not currently active</h2></div>;
}
return (
<GenericForm {...formData} />
);
}
export default FormActiveRedirect;
+1
View File
@@ -22,6 +22,7 @@ export interface UserInput {
}
export type FormData = {
backendFormName: string;
steps: Step[];
backend: string;
userInput: UserInput;
+1 -2
View File
@@ -1,10 +1,9 @@
import React, {useState} from "react";
import './GenericForm.css';
import {useNavigate} from 'react-router-dom'
import {ErrorMessage, Field, Form, FormikProvider, FormikValues, useFormik} from "formik";
import {ErrorMessage, Form, FormikProvider, FormikValues, useFormik} from "formik";
import {Step, UserInput, FormData} from './formInterfaces';
import * as Yup from "yup";
import formHTML from "./formHTML";
import FormHTML from "./formHTML";
const GenericForm = (formData: FormData) => {