Compare commits

...

5 Commits

Author SHA1 Message Date
Teriuihi 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
Teriuihi 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
Teriuihi 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
Teriuihi 67eddc0394 Merge branch 'refs/heads/dev' 2024-08-10 00:26:46 +02:00
Teriuihi 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 53 additions and 7 deletions

12
Jenkinsfile vendored
View File

@ -39,6 +39,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,8 +62,10 @@ pipeline {
}
stage('discord') {
when {
branch 'main'
branch 'master'
anyOf {
branch 'main'
branch 'master'
}
}
steps {
discordSend description: "Build: ${BUILD_NUMBER}", showChangeset: true, result: currentBuild.currentResult, title: currentBuild.fullProjectName, webhookURL: env.discordwebhook

View File

@ -9,6 +9,7 @@ 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 +22,7 @@ function App() {
<Route
key={property.path}
path={property.path}
element={<GenericForm {...property.formData} />}
element={<FormActiveRedirect {...property.formData} />}
/>
))}
<Route path="/verify-email" element={<VerifyMail/>}/>

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",
};

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",
};

View File

@ -0,0 +1,35 @@
import {FormData} from "./formInterfaces";
import {useEffect, useState} from "react";
import GenericForm from "./genericForm";
const FormActiveRedirect = (formData: FormData) => {
const [isLoading, setLoading] = useState(true);
const [isFormActive, setFormActive] = useState(false);
const handleCheckForm = 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);
};
useEffect(() => {
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;

View File

@ -22,6 +22,7 @@ export interface UserInput {
}
export type FormData = {
backendFormName: string;
steps: Step[];
backend: string;
userInput: UserInput;

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) => {