dsql-admin/dsql-app/.local_dist/server/pages/unsubscribe.js

333 lines
15 KiB
JavaScript
Raw Normal View History

2024-11-05 11:12:42 +00:00
"use strict";
(() => {
var exports = {};
exports.id = 5785;
exports.ids = [5785];
exports.modules = {
/***/ 5591:
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "default": () => (/* binding */ Contact),
/* harmony export */ "getServerSideProps": () => (/* binding */ getServerSideProps)
/* harmony export */ });
/* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(997);
/* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(6689);
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var _components_general_LoadingBlock__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(5264);
/* harmony import */ var _components_general_PageHeadTags__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(4097);
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(370);
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_4__);
/* harmony import */ var _functions_frontend_fetchApi__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(6729);
/* harmony import */ var _layouts_GeneralLayout__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(6217);
/* harmony import */ var _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(9395);
/* harmony import */ var _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_6___default = /*#__PURE__*/__webpack_require__.n(_package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_6__);
// @ts-check
/**
* ==============================================================================
* Imports
* ==============================================================================
*/
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
* ==============================================================================
* Main Component { Functional }
* ==============================================================================
* @param {Object} props - Server props
* @param {import("@/package-shared/types").UserType | null} props.user
* @param {string | null} props.email
* @param {string} props.productionEnvironment
* @param {any} props.existingAlerts
*/ function Contact({ user , email , productionEnvironment , existingAlerts , }) {
/**
* Get Contexts
*
* @abstract { React.useContext }
*/ ////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/**
* Javascript Variables
*
* @abstract Non hook variables and functions
*/ const pageTitle = "Unsubscribe | Datasquirel";
const pageDescription = "Unsubscribe from email alerts";
let head = /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)(react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.Fragment, {
children: [
/*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("title", {
children: pageTitle
}),
/*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("meta", {
name: "description",
content: pageDescription
}),
/*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_components_general_PageHeadTags__WEBPACK_IMPORTED_MODULE_3__/* ["default"] */ .Z, {
pageTitle: pageTitle,
pageDescription: pageDescription,
pagePathname: "/unsubscribe"
})
]
});
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/**
* React Hooks
*
* @abstract { useState, useEffect, useRef, etc ... }
*/ const [loading, setLoading] = react__WEBPACK_IMPORTED_MODULE_1___default().useState(false);
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/**
* Function Return
*
* @abstract Main Function Return
*/ return /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx((react__WEBPACK_IMPORTED_MODULE_1___default().Fragment), {
children: /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_layouts_GeneralLayout__WEBPACK_IMPORTED_MODULE_5__/* ["default"] */ .Z, {
head: head,
user: user,
productionEnvironment: productionEnvironment,
children: /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("main", {
children: /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("section", {
children: [
loading && /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_components_general_LoadingBlock__WEBPACK_IMPORTED_MODULE_2__/* ["default"] */ .Z, {}),
/*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div", {
className: "flex-col",
children: [
/*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("h1", {
className: "text-2xl",
children: "Unsubscribe from Email alerts"
}),
!email && /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("p", {
className: "max-w-md",
children: [
"No email please ",
/*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("a", {
href: "/login",
children: "Login"
}),
" ",
"to Access Email Subscriptions or click on",
" ",
/*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("i", {
children: '"unsubscribe"'
}),
" from your mail box"
]
}),
email && /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("form", {
className: "flex flex-col items-start gap-4",
onSubmit: (e)=>{
e.preventDefault();
setLoading(true);
/** @type {HTMLFormElement} */ // @ts-ignore
const formEl = e.target;
(0,_functions_frontend_fetchApi__WEBPACK_IMPORTED_MODULE_7__/* ["default"] */ .Z)("/api/unsubscribe", {
method: "post",
body: {
email: email,
alerts: formEl["alerts_checkbox"].checked,
userId: user?.id ? user.id : null
}
}).then((res)=>{
console.log(res);
setLoading(false);
});
},
children: [
/*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("span", {
className: "bg-slate-100 py-1 px-3 rounded-full",
children: email
}),
/*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div", {
className: "flex items-center gap-1",
children: [
/*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("input", {
type: "checkbox",
name: "alerts_checkbox",
id: "alerts_checkbox",
defaultChecked: existingAlerts ? true : false,
className: "w-6 h-6"
}),
/*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("label", {
htmlFor: "alerts_checkbox",
className: "text-base whitespace-nowrap text-slate-800",
children: "Alerts"
})
]
}),
/*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("button", {
children: "Save Settings"
})
]
})
]
})
]
})
})
})
});
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
}
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
* ==============================================================================
* Server Side Props or Static Props
* ==============================================================================
* @type {import("next").GetServerSideProps}
*/ async function getServerSideProps({ req , res , query }) {
// ## Environment processes
const productionEnvironment = process.env.DSQL_HOST_ENV;
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/**
* User Authentication
*
* @description User authentication
*/ const user = await _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_4___default()(req, res);
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/**
* Page/Site Data Data Fetching
*
* @description Fetch data on the server before returning
*/ const email = query.email ? query.email : user?.email ? user.email : null;
let existingAlerts = await _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_6___default()(`SELECT email FROM unsubscribes WHERE email='${email}' AND type='alerts'`);
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/**
* Server props return
*
* @description Return data fetched on the server side
*/ return {
props: {
user: user,
email: email,
productionEnvironment,
existingAlerts: existingAlerts[0] ? false : true
}
};
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
}
/***/ }),
/***/ 386:
/***/ ((module) => {
module.exports = require("@mui/icons-material/CottageTwoTone");
/***/ }),
/***/ 5557:
/***/ ((module) => {
module.exports = require("@mui/icons-material/MenuBookTwoTone");
/***/ }),
/***/ 2423:
/***/ ((module) => {
module.exports = require("lucide-react");
/***/ }),
/***/ 968:
/***/ ((module) => {
module.exports = require("next/head");
/***/ }),
/***/ 6689:
/***/ ((module) => {
module.exports = require("react");
/***/ }),
/***/ 997:
/***/ ((module) => {
module.exports = require("react/jsx-runtime");
/***/ }),
/***/ 2261:
/***/ ((module) => {
module.exports = require("serverless-mysql");
/***/ }),
/***/ 4300:
/***/ ((module) => {
module.exports = require("buffer");
/***/ }),
/***/ 6113:
/***/ ((module) => {
module.exports = require("crypto");
/***/ }),
/***/ 7147:
/***/ ((module) => {
module.exports = require("fs");
/***/ }),
/***/ 3685:
/***/ ((module) => {
module.exports = require("http");
/***/ }),
/***/ 1017:
/***/ ((module) => {
module.exports = require("path");
/***/ })
};
;
// load runtime
var __webpack_require__ = require("../webpack-runtime.js");
__webpack_require__.C(exports);
var __webpack_exec__ = (moduleId) => (__webpack_require__(__webpack_require__.s = moduleId))
2024-11-05 14:18:40 +00:00
var __webpack_exports__ = __webpack_require__.X(0, [4017,8313,5264,6729,5449,913,4480,370,9360,6217,4097], () => (__webpack_exec__(5591)));
2024-11-05 11:12:42 +00:00
module.exports = __webpack_exports__;
})();