Added contact us structure for sending data to backend #13

Merged
ameye merged 1 commits from contact-us into master 2025-12-16 12:15:34 +00:00
4 changed files with 172 additions and 47 deletions
+61
View File
@@ -0,0 +1,61 @@
import axios from "axios"
axios.interceptors.request.use(
config => {
config.headers = {
Accept: "application/json",
"Access-Control-Allow-Origin": "*",
// "Access-Control-Expose-Headers": "Access-Control-Allow-Origin",
// "Access-Control-Allow-Headers": "Origin, X-API-KEY, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method, Access-Control-Allow-Headers, Authorization, observe, enctype, Content-Length, X-Csrf-Token",
// "Content-Type": "application/json;charset=UTF-8",
// 'Authorization': (localStorage && localStorage.getItem('access_token')) ? `Bearer ${localStorage.getItem('access_token')}` : '',
};
// config.headers['Authorization'] = `Bearer ${localStorage.getItem('token')}`;
// config.baseURL = process.env.REACT_APP_MAIN_API
return config;
},
error => {
return Promise.reject(error);
}
);
const postAuxEnd = (path, postData, media=false) => {
const basePath = media ? 'https://blogdata.chiefsoft.net' : 'https://blogdata.chiefsoft.net'
let newPostData = {}
if(!media){
newPostData = {...postData}
}else{
newPostData = new FormData();
for (let data in postData) {
newPostData.append(data, postData[data]);
}
}
return axios.post(`${basePath}${path}`, newPostData).then(res => {
return res
}).catch(err => {
// throw new Error(err.response.data.error_message);
throw new Error(err);
})
}
const getAuxEnd = (path, reqData= null) => {
const basePath = 'https://blogdata.chiefsoft.net'
return axios.get(`${basePath}${path}`,{ params: reqData }).then(res => {
return res
// localStorage.clear();
// window.location.href = `/login?sessionExpired=true`;
}).catch(err => {
throw new Error(err);
// throw new Error(err.response.data.message);
// return err
})
}
// FUNCTION TO GET MERMS BLOGS
export const getMermsBlogs = (reqData) => {
let postData = {
...reqData
}
return getAuxEnd('/mermsblogdata/mermsemr', postData, false)
}
+4 -1
View File
@@ -12,8 +12,10 @@
}, },
"dependencies": { "dependencies": {
"@tanstack/react-query": "^5.62.16", "@tanstack/react-query": "^5.62.16",
"axios": "^1.13.2",
"eslint": "8.41.0", "eslint": "8.41.0",
"eslint-config-next": "13.4.3", "eslint-config-next": "13.4.3",
"formik": "^2.4.9",
"next": "^13.5.8", "next": "^13.5.8",
"react": "18.2.0", "react": "18.2.0",
"react-dom": "18.2.0", "react-dom": "18.2.0",
@@ -21,6 +23,7 @@
"sass": "^1.62.1", "sass": "^1.62.1",
"server-only": "^0.0.1", "server-only": "^0.0.1",
"swiper": "^10.0.4", "swiper": "^10.0.4",
"wowjs": "^1.1.3" "wowjs": "^1.1.3",
"yup": "^1.7.1"
} }
} }
+104 -46
View File
@@ -1,7 +1,49 @@
import { useMutation } from '@tanstack/react-query';
import Layout from "../components/layout/Layout" import Layout from "../components/layout/Layout"
import Link from "next/link" import Link from "next/link"
import { Form, Formik } from 'formik';
import * as Yup from "yup";
export default function Home() { export default function Home() {
const validationSchema = Yup.object().shape({
subject: Yup.string().required("Required"),
name: Yup.string().required("Required"),
email: Yup.string().required("Required"),
message: Yup.string().required("Required"),
})
const initialValues = {
subject: '',
name: '',
email: '',
message: ''
};
const contactMutation = useMutation({
mutationFn: (fields) => {
return null //completePWDReset(fields)
},
onSuccess: (res) => {
if(res?.data?.resultCode != '0'){
throw({message: res?.data?.resultDescription})
}
},
// onError: (err) => {
// console.log('err', err)
// }
})
const handleContactMutation = (values) => {
let reqData = {
...values
}
console.log(reqData)
setTimeout(()=>{
contactMutation.reset()
},3000)
// contactMutation.mutate(reqData)
}
return ( return (
<> <>
<Layout headerStyle={1} footerStyle={3} headerCls="navbar-dark inner-page-header"> <Layout headerStyle={1} footerStyle={3} headerCls="navbar-dark inner-page-header">
@@ -25,52 +67,68 @@ export default function Home() {
<div className="row justify-content-center"> <div className="row justify-content-center">
<div className="col-md-11 col-lg-10 col-xl-8"> <div className="col-md-11 col-lg-10 col-xl-8">
<div className="form-holder"> <div className="form-holder">
<form name="contactform" className="row contact-form"> <Formik
{/* Form Select */} initialValues={initialValues}
<div className="col-md-12 input-subject"> validationSchema={validationSchema}
<p className="p-lg">This question is about: </p> onSubmit={handleContactMutation}
<span>Choose a topic, so we know who to send your request to: </span> >
<select className="form-select subject" aria-label="Default select example"> {(props) => {
<option>This question is about...</option> return (
<option>Registering/Authorising</option> <Form name="contactform" className="row contact-form">
<option>Using Application</option> {/* Form Select */}
<option>Troubleshooting</option> <div className="col-md-12 input-subject">
<option>Backup/Restore</option> <p className="p-lg">This question is about:{(props.errors.subject && props.touched.subject) && <span style={{display: 'inline'}} className='text-danger'>{props.errors.subject}</span>}</p>
<option>Other</option> <span>Choose a topic, so we know who to send your request to: </span>
</select> <select name='subject' onChange={props.handleChange} className="form-select subject" aria-label="Default select example">
</div> <option value=''>This question is about...</option>
{/* Contact Form Input */} <option value='registering/authorising'>Registering/Authorising</option>
<div className="col-md-12"> <option value='using application'>Using Application</option>
<p className="p-lg">Your Name: </p> <option value='troubleshooting'>Troubleshooting</option>
<span>Please enter your real name: </span> <option value='backup/restore'>Backup/Restore</option>
<input type="text" name="name" className="form-control name" placeholder="Your Name*" /> <option value='others'>Other</option>
</div> </select>
<div className="col-md-12"> </div>
<p className="p-lg">Your Email Address: </p> {/* Contact Form Input */}
<span>Please carefully check your email address for accuracy</span> <div className="col-md-12">
<input type="text" name="email" className="form-control email" placeholder="Email Address*" /> <p className="p-lg">Your Name:{(props.errors.name && props.touched.name) && <span style={{display: 'inline'}} className='text-danger'>{props.errors.name}</span>}</p>
</div> <span>Please enter your real name: </span>
<div className="col-md-12"> <input type="text" onChange={props.handleChange} name="name" className="form-control name" placeholder="Your Name*" />
<p className="p-lg">Explain your question in details: </p> </div>
<span>Your OS version, MERMS version &amp; build, steps you did. Be VERY precise!</span> <div className="col-md-12">
<textarea className="form-control message" name="message" rows={6} placeholder="I have a problem with..." /> <p className="p-lg">Your Email Address:{(props.errors.email && props.touched.email) && <span style={{display: 'inline'}} className='text-danger'>{props.errors.email}</span>}</p>
</div> <span>Please carefully check your email address for accuracy</span>
{/* Contact Form Button */} <input type="text" onChange={props.handleChange} name="email" className="form-control email" placeholder="Email Address*" />
<div className="col-md-12 mt-15 form-btn text-right"> </div>
<button type="submit" className="btn btn--theme hover--theme submit">Submit Request</button> <div className="col-md-12">
</div> <p className="p-lg">Explain your question in details:{(props.errors.message && props.touched.message) && <span style={{display: 'inline'}} className='text-danger'>{props.errors.message}</span>}</p>
<div className="contact-form-notice"> <span>Your OS version, MERMS version &amp; build, steps you did. Be VERY precise!</span>
<p className="p-sm">We are committed to your privacy. MERMS uses the information you <textarea onChange={props.handleChange} className="form-control message" name="message" rows={6} placeholder="I have a problem with..." />
provide us to contact you about our relevant content, products, and services. </div>
You may unsubscribe from these communications at any time. For more information, {/* Contact Form Button */}
check out our <Link href="/privacy">Privacy Policy</Link>. <div className="col-md-12 mt-15 form-btn text-right">
</p> <button
</div> type="submit"
{/* Contact Form Message */} className="btn btn--theme hover--theme submit"
<div className="col-lg-12 contact-form-msg"> disabled={contactMutation.isPending || contactMutation.isSuccess}
<span className="loading" /> >
</div> {contactMutation.isPending ? 'Sending' : contactMutation.isSuccess ? 'Message Sent' : 'Submit Request'}
</form> </button>
</div>
<div className="contact-form-notice">
<p className="p-sm">We are committed to your privacy. MERMS uses the information you
provide us to contact you about our relevant content, products, and services.
You may unsubscribe from these communications at any time. For more information,
check out our <Link href="/privacy">Privacy Policy</Link>.
</p>
</div>
{/* Contact Form Message */}
<div className="col-lg-12 contact-form-msg">
<span className="loading" />
</div>
</Form>
);
}}
</Formik>
</div> </div>
</div> </div>
</div> {/* END CONTACT FORM */} </div> {/* END CONTACT FORM */}
+3
View File
@@ -5,11 +5,14 @@ import Layout from "../components/layout/Layout"
import Link from "next/link" import Link from "next/link"
import queryKeys from "../components/queryclientProvider/queryKeys"; import queryKeys from "../components/queryclientProvider/queryKeys";
import MermsBlogFix from "../components/sections/MermsBlogFix"; import MermsBlogFix from "../components/sections/MermsBlogFix";
import { getMermsBlogs } from "../components/services/services";
export default function Home() { export default function Home() {
const {data, isFetching, isError, error} = useQuery({ const {data, isFetching, isError, error} = useQuery({
queryKey: queryKeys.blog, queryKey: queryKeys.blog,
// queryFn: () => getMermsBlogs(),
staleTime: 0,
queryFn: async () => { queryFn: async () => {
try { try {
const blog_url = 'https://blogdata.chiefsoft.net/mermsblogdata/mermsemr'; const blog_url = 'https://blogdata.chiefsoft.net/mermsblogdata/mermsemr';