diff --git a/actions/index.js b/actions/index.js index 54f06b8..aa0c514 100644 --- a/actions/index.js +++ b/actions/index.js @@ -8,4 +8,5 @@ export * from './navigationActions'; export * from './formsActions'; export * from './settingsActions'; export * from './announcementsActions'; -export * from './eventsActions'; \ No newline at end of file +export * from './eventsActions'; +export * from './supportActions'; \ No newline at end of file diff --git a/actions/supportActions.js b/actions/supportActions.js new file mode 100644 index 0000000..1bb9656 --- /dev/null +++ b/actions/supportActions.js @@ -0,0 +1,80 @@ +import axios from 'axios'; + +import * as actionTypes from '../constants/actionTypes'; +import * as currentState from '../reducers/initialState'; + +if(process.browser) +{ + FormData.prototype.appendObject = function(obj, namespace) + { + let keyName; + for (var key in obj) + { + if (obj.hasOwnProperty(key)) + { + keyName = [namespace, '[', key, ']'].join(''); + this.append(keyName, obj[key]); + } + } + }; +} + +export const getSupportThemes = ({ dispatch, query, }) => +{ + console.log("ACTION", "support", "getSupportThemes", { query }); + + return new Promise((resolve, reject) => + { + axios.post(`${ process.env.NEXT_PUBLIC_SELF_API_HOST }/api/support/themes`, { + query + }, + { + withCredentials: true, + }) + .then(async (response) => + { + console.log("getContractRules", "response.data", response.data); + dispatch({ type: actionTypes.SUPPORT_THEMES, data: { themes: response.data.themes } }); + + resolve(); + }) + .catch((error) => + { + console.error(error); + reject(); + }); + }); +} + +export const sendNewAppeal = ({ name, phone, email, company }) => +{ + return new Promise((resolve, reject) => + { + var formData = new FormData(); + formData.append("form", "FORM_LEASING_REQUESTS"); + formData.append("FORM_FIELD_FIO", name); + formData.append("FORM_FIELD_PHONE", phone); + formData.append("FORM_FIELD_EMAIL", email); + formData.append("FORM_FIELD_COMPANY", company); + formData.append("FORM_FIELD_PAGE_NAME", document.title); + formData.append("FORM_FIELD_PAGE_URL", window.location.href); + + axios.post(`${ process.env.NEXT_PUBLIC_API_HOST }/api/forms/`, formData) + .then((response) => + { + if(response.data.status === "complete") + { + resolve(); + } + else + { + reject(); + } + }) + .catch((error) => + { + console.error(error); + reject(); + }); + }); +} \ No newline at end of file diff --git a/constants/actionTypes.js b/constants/actionTypes.js index 3a2b11e..3b97b6a 100644 --- a/constants/actionTypes.js +++ b/constants/actionTypes.js @@ -23,4 +23,9 @@ export const CONTRACT_CALCULATED = 'CONTRACT_CALCULATED'; export const CALENDAR = 'CALENDAR'; export const EVENTS = 'EVENTS'; -export const EVENTS_FILTERED = 'EVENTS_FILTERED'; \ No newline at end of file +export const EVENTS_FILTERED = 'EVENTS_FILTERED'; + +export const SUPPORT_THEMES = 'SUPPORT_THEMES'; +export const SUPPORT_THEMES_SEARCHED = 'SUPPORT_THEMES_SEARCHED'; +export const SUPPORT_APPEALS = 'SUPPORT_APPEALS'; +export const SUPPORT_APPEAL = 'SUPPORT_APPEAL'; \ No newline at end of file diff --git a/next.config.js b/next.config.js index 49aeaf0..4931a14 100644 --- a/next.config.js +++ b/next.config.js @@ -32,7 +32,7 @@ module.exports = withImages(withFonts(withLess({ return [ { source: '/support', - destination: '/support/faq/', + destination: '/support/faq', permanent: false, }, //{ diff --git a/pages/api/support/themes.js b/pages/api/support/themes.js new file mode 100644 index 0000000..9e6eb03 --- /dev/null +++ b/pages/api/support/themes.js @@ -0,0 +1,53 @@ +// Next.js API route support: https://nextjs.org/docs/api-routes/introduction +import axios from 'axios'; +import { Cookies } from 'react-cookie'; +import cookie from 'cookie'; +import moment from 'moment'; +import jwt from 'jsonwebtoken'; +import { cors } from '../../../lib/cors'; + +export default async function handler(req, res) +{ + await cors(req, res); + + if(req.headers.cookie !== undefined) + { + const cookies = cookie.parse(req.headers?.cookie ? req.headers?.cookie : ""); + if(cookies.jwt !== undefined && cookies.jwt !== null) + { + if(jwt.verify(cookies.jwt, process.env.JWT_SECRET_CLIENT)) + { + const response = await new Promise((resolve, reject) => + { + axios.post(`${ process.env.NEXT_PUBLIC_API_HOST }/api/account/support/themes/`, { + query: req.body.query, + }) + .then((api_response) => + { + console.log("RESPONSE"); + console.log(api_response.data); + + resolve(api_response.data); + }) + .catch((error) => + { + console.log("error"); + console.error(error); + + reject([]); + }); + }); + + res.status(200).json(response); + } + else + { + res.status(403); + } + } + else + { + res.status(403); + } + } +} \ No newline at end of file diff --git a/pages/components/Header/index.js b/pages/components/Header/index.js index c1da00a..952c56d 100644 --- a/pages/components/Header/index.js +++ b/pages/components/Header/index.js @@ -168,36 +168,32 @@ class Header extends React.Component