- {bodyshop.logo_img_path && bodyshop.logo_img_path.src ? (
-

- ) : null}
-
-
{bodyshop.shopname || ""}
-
{`${bodyshop.address1 || ""}`}
-
{`${bodyshop.address2 || ""}`}
-
{`${bodyshop.city || ""} ${bodyshop.state || ""} ${
- bodyshop.zip_post || ""
- }`}
+ if (submitting.loading) return
;
+
+ const handleFinish = async (values) => {
+ try {
+ setSubmitting({ ...submitting, loading: true, submitting: true });
+ const result = await axios.post("/csi/submit", { surveyId, values });
+ console.log("result", result);
+ if (!!!result.errors && result.data.update_csi.affected_rows > 0) {
+ setSubmitting({ ...submitting, loading: false, submitted: true });
+ }
+ } catch (error) {
+ console.error(`Something went wrong...: ${error.message}`);
+ console.dir({
+ stack: error?.stack,
+ message: error?.message,
+ });
+ }
+ };
+
+ if (!axiosResponse || axiosResponse.csi_by_pk === null) {
+ // Do something here , this is where you would return a loading box or something
+ return (
+ <>
+
+
+
+
+
+ {`Copyright ImEX.Online. Survey ID: ${surveyId}`}
+
+
+ >
+ );
+ } else {
+ const {
+ relateddata: { bodyshop, job },
+ csiquestion: { config: csiquestions },
+ } = axiosResponse.csi_by_pk;
+
+ return (
+
+
+
+ {bodyshop.logo_img_path && bodyshop.logo_img_path.src ? (
+

+ ) : null}
+
+
+ {bodyshop.shopname || ""}
+
+
+ {`${bodyshop.address1 || ""}${bodyshop.address2 ? ", " : ""}${
+ bodyshop.address2 || ""
+ }`.trim()}
+
+
+ {`${bodyshop.city || ""}${
+ bodyshop.city && bodyshop.state ? ", " : ""
+ }${bodyshop.state || ""} ${bodyshop.zip_post || ""}`.trim()}
+
+
+
{t("csi.labels.title")}
+
+ {t("csi.labels.greeting", {
+ name: job.ownr_co_nm || job.ownr_fn || "",
+ })}
+
+
+ {t("csi.labels.intro", { shopname: bodyshop.shopname || "" })}
+
- {t("csi.labels.title")}
- {`Hi ${job.ownr_co_nm || job.ownr_fn || ""}!`}
-
- {`At ${
- bodyshop.shopname || ""
- }, we value your feedback. We would love to
- hear what you have to say. Please fill out the form below.`}
-
-
- {submitting.error ? (
-
- ) : null}
+ {submitting.error ? (
+
+ ) : null}
- {submitting.submitted ? (
-
-
-
- ) : (
-
-
-
- )}
-
-
- {`Copyright ImEX.Online. Survey ID: ${surveyId}`}
-
-
- );
+ {submitting.submitted ? (
+
+
+
+ ) : (
+
+
+
+ )}
+
+ {t("csi.labels.copyright")}{" "}
+ {t("csi.fields.surveyid", { surveyId: surveyId })}
+
+
+ );
+ }
}
diff --git a/client/src/translations/en_us/common.json b/client/src/translations/en_us/common.json
index 7679ffeed..c73b84bef 100644
--- a/client/src/translations/en_us/common.json
+++ b/client/src/translations/en_us/common.json
@@ -838,17 +838,23 @@
"creating": "Error creating survey {{message}}",
"notconfigured": "You do not have any current CSI Question Sets configured.",
"notfoundsubtitle": "We were unable to find a survey using the link you provided. Please ensure the URL is correct or reach out to your shop for more help.",
- "notfoundtitle": "No survey found."
+ "notfoundtitle": "No survey found.",
+ "surveycompletetitle": "Survey previously completed",
+ "surveycompletesubtitle": "This survey was already completed on {{date}}."
},
"fields": {
"completedon": "Completed On",
- "created_at": "Created At"
+ "created_at": "Created At",
+ "surveyid": "Survey ID {{surveyId}}"
},
"labels": {
"nologgedinuser": "Please log out of ImEX Online",
"nologgedinuser_sub": "Users of ImEX Online cannot complete CSI surveys while logged in. Please log out and try again.",
"noneselected": "No response selected.",
- "title": "Customer Satisfaction Survey"
+ "title": "Customer Satisfaction Survey",
+ "greeting": "Hi {{name}}!",
+ "intro": "At {{shopname}}, we value your feedback. We would love to hear what you have to say. Please fill out the form below.",
+ "copyright": "Copyright © $t(titles.app). All Rights Reserved."
},
"successes": {
"created": "CSI created successfully. ",
diff --git a/server.js b/server.js
index 1eaa4b8ec..dbb0d0a5e 100644
--- a/server.js
+++ b/server.js
@@ -74,6 +74,7 @@ app.use('/adm', require("./server/routes/adminRoutes"));
app.use('/tech', require("./server/routes/techRoutes"));
app.use('/intellipay', require("./server/routes/intellipayRoutes"));
app.use('/cdk', require("./server/routes/cdkRoutes"));
+app.use('/csi', require("./server/routes/csiRoutes"));
// Default route for forbidden access
app.get("/", (req, res) => {
diff --git a/server/csi/csi.js b/server/csi/csi.js
new file mode 100644
index 000000000..819a9ebc7
--- /dev/null
+++ b/server/csi/csi.js
@@ -0,0 +1,2 @@
+exports.lookup = require("./lookup").default;
+exports.submit = require("./submit").default;
\ No newline at end of file
diff --git a/server/csi/lookup.js b/server/csi/lookup.js
new file mode 100644
index 000000000..48154cdb8
--- /dev/null
+++ b/server/csi/lookup.js
@@ -0,0 +1,24 @@
+const path = require("path");
+const queries = require("../graphql-client/queries");
+const logger = require("../utils/logger");
+require("dotenv").config({
+ path: path.resolve(
+ process.cwd(),
+ `.env.${process.env.NODE_ENV || "development"}`
+ ),
+});
+
+const client = require("../graphql-client/graphql-client").client;
+
+exports.default = async (req, res) => {
+ try {
+ logger.log("csi-surveyID-lookup", "DEBUG", "csi", req.body.surveyId, null);
+ const response = await client.request(queries.QUERY_SURVEY, {
+ surveyId: req.body.surveyId,
+ });
+ res.status(200).json(response);
+ } catch (error) {
+ logger.log("csi-surveyID-lookup", "ERROR", "csi", req.body.surveyId, error);
+ res.status(400).json(error);
+ }
+};
diff --git a/server/csi/submit.js b/server/csi/submit.js
new file mode 100644
index 000000000..da5727531
--- /dev/null
+++ b/server/csi/submit.js
@@ -0,0 +1,29 @@
+const path = require("path");
+const queries = require("../graphql-client/queries");
+const logger = require("../utils/logger");
+require("dotenv").config({
+ path: path.resolve(
+ process.cwd(),
+ `.env.${process.env.NODE_ENV || "development"}`
+ ),
+});
+
+const client = require("../graphql-client/graphql-client").client;
+
+exports.default = async (req, res) => {
+ try {
+ logger.log("csi-surveyID-submit", "DEBUG", "csi", req.body.surveyId, null);
+ const response = await client.request(queries.COMPLETE_SURVEY, {
+ surveyId: req.body.surveyId,
+ survey: {
+ response: req.body.values,
+ valid: false,
+ completedon: new Date(),
+ },
+ });
+ res.status(200).json(response);
+ } catch (error) {
+ logger.log("csi-surveyID-submit", "ERROR", "csi", req.body.surveyId, error);
+ res.status(400).json(error);
+ }
+};
diff --git a/server/graphql-client/queries.js b/server/graphql-client/queries.js
index fe1c7b6e5..b2fd4e23e 100644
--- a/server/graphql-client/queries.js
+++ b/server/graphql-client/queries.js
@@ -2156,3 +2156,23 @@ exports.ACTIVE_SHOP_BY_USER = `query ACTIVE_SHOP_BY_USER($user: String) {
shopid
}
}`;
+
+exports.QUERY_SURVEY = `query QUERY_SURVEY($surveyId: uuid!) {
+ csi_by_pk(id: $surveyId) {
+ completedon
+ csiquestion {
+ id
+ config
+ }
+ id
+ relateddata
+ valid
+ validuntil
+ }
+}`;
+
+exports.COMPLETE_SURVEY = `mutation COMPLETE_SURVEY($surveyId: uuid!, $survey: csi_set_input) {
+ update_csi(where: { id: { _eq: $surveyId } }, _set: $survey) {
+ affected_rows
+ }
+ }`;
\ No newline at end of file
diff --git a/server/routes/csiRoutes.js b/server/routes/csiRoutes.js
new file mode 100644
index 000000000..8f47a2b2d
--- /dev/null
+++ b/server/routes/csiRoutes.js
@@ -0,0 +1,8 @@
+const express = require("express");
+const router = express.Router();
+const { lookup, submit } = require("../csi/csi");
+
+router.post("/lookup", lookup);
+router.post("/submit", submit);
+
+module.exports = router;