424 lines
22 KiB
JavaScript
424 lines
22 KiB
JavaScript
"use strict";
|
|
exports.id = 5114;
|
|
exports.ids = [5114];
|
|
exports.modules = {
|
|
|
|
/***/ 5114:
|
|
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
|
|
|
|
// EXPORTS
|
|
__webpack_require__.d(__webpack_exports__, {
|
|
"Z": () => (/* binding */ CreateAccountForm)
|
|
});
|
|
|
|
// EXTERNAL MODULE: external "react/jsx-runtime"
|
|
var jsx_runtime_ = __webpack_require__(997);
|
|
// EXTERNAL MODULE: external "react"
|
|
var external_react_ = __webpack_require__(6689);
|
|
var external_react_default = /*#__PURE__*/__webpack_require__.n(external_react_);
|
|
// EXTERNAL MODULE: ./functions/frontend/fetchApi.js
|
|
var fetchApi = __webpack_require__(6729);
|
|
;// CONCATENATED MODULE: ./functions/frontend/submitNewUserForm.js
|
|
// @ts-check
|
|
|
|
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
|
* # Submit New Image Form
|
|
* @param {object} param0
|
|
* @param {*} param0.e
|
|
* @param {React.Dispatch<React.SetStateAction<boolean>>} param0.setLoading
|
|
* @param {import("@/package-shared/types").UserType} [param0.user]
|
|
* @param {*} [param0.image]
|
|
* @param {*} [param0.query]
|
|
*/ async function submitNewUserForm({ e , setLoading , user , image , query , }) {
|
|
////////////////////////////////////////
|
|
////////////////////////////////////////
|
|
////////////////////////////////////////
|
|
setLoading(true);
|
|
////////////////////////////////////////
|
|
////////////////////////////////////////
|
|
////////////////////////////////////////
|
|
let formBody = {
|
|
first_name: e.target["first_name"].value,
|
|
last_name: e.target["last_name"].value,
|
|
email: user ? null : e.target["email_address"].value,
|
|
username: user ? null : e.target["username"].value,
|
|
password: user ? null : e.target["password"].value,
|
|
image: image ? image : null
|
|
};
|
|
// @ts-ignore
|
|
if (query?.invite) formBody["inviteObject"] = query;
|
|
////////////////////////////////////////
|
|
////////////////////////////////////////
|
|
////////////////////////////////////////
|
|
const apiRoute = user ? "/api/updateUser" : "/api/registerUser";
|
|
(0,fetchApi/* default */.Z)(apiRoute, {
|
|
method: "post",
|
|
body: formBody
|
|
}, user ? true : false).then((res)=>{
|
|
console.log(res);
|
|
if (!user && res?.insertId) {
|
|
localStorage.setItem("id", res.insertId);
|
|
(0,fetchApi/* default */.Z)("/api/loginUser", {
|
|
method: "post",
|
|
body: {
|
|
email: formBody.email,
|
|
password: formBody.password
|
|
}
|
|
}).then((_res)=>{
|
|
console.log(_res);
|
|
localStorage.setItem("csrf", _res.user.csrf_k);
|
|
localStorage.setItem("stripe_id", _res.user.stripe_id);
|
|
localStorage.setItem("user", JSON.stringify(_res.userPayload));
|
|
window.location.href = "/admin";
|
|
});
|
|
} else if (user && res?.user) {
|
|
// fetchApi("/api/reauthUser")
|
|
window.location.reload();
|
|
} else if (res?.msg) {
|
|
alert(res.msg);
|
|
}
|
|
}).catch((err)=>{
|
|
console.log(err);
|
|
}).finally(()=>{
|
|
setTimeout(()=>{
|
|
setLoading(false);
|
|
}, 2000);
|
|
});
|
|
} /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */
|
|
|
|
// EXTERNAL MODULE: ./components/general/FormAlertBlock.jsx
|
|
var FormAlertBlock = __webpack_require__(7037);
|
|
// EXTERNAL MODULE: ./components/general/LoadingBlock.jsx
|
|
var LoadingBlock = __webpack_require__(5264);
|
|
// EXTERNAL MODULE: ./components/pages/login/SocialLogin.jsx + 3 modules
|
|
var SocialLogin = __webpack_require__(8374);
|
|
;// CONCATENATED MODULE: ./components/pages/create-account/CreateAccountForm.jsx
|
|
// @ts-check
|
|
/**
|
|
* ==============================================================================
|
|
* Imports
|
|
* ==============================================================================
|
|
*/
|
|
|
|
////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////
|
|
/** @type {any} */ let timeout;
|
|
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
|
* ==============================================================================
|
|
* Main Component { Functional }
|
|
* ==============================================================================
|
|
* @param {Object} props - Server props
|
|
* @param {import("@/package-shared/types").UserType} [props.user]
|
|
* @param {import("@/package-shared/types").CreateAccountQueryType} [props.query]
|
|
* @param {any} [props.image]
|
|
*/ function CreateAccountForm({ user , query , image }) {
|
|
/**
|
|
* Get Contexts
|
|
*
|
|
* @abstract { React.useContext }
|
|
*/ ////////////////////////////////////////
|
|
////////////////////////////////////////
|
|
////////////////////////////////////////
|
|
/**
|
|
* Javascript Variables
|
|
*
|
|
* @abstract Non hook variables and functions
|
|
*/ const defaultEmail = query?.email ? query.email : user?.email ? user.email : "";
|
|
////////////////////////////////////////
|
|
////////////////////////////////////////
|
|
////////////////////////////////////////
|
|
/**
|
|
* React Hooks
|
|
*
|
|
* @abstract { useState, useEffect, useRef, etc ... }
|
|
*/ /** @type {[ alert: string | null, setAlert: React.Dispatch<React.SetStateAction<string | null>> ]} */ // @ts-ignore
|
|
const [alert, setAlert] = external_react_default().useState(null);
|
|
const [loading, setLoading] = external_react_default().useState(false);
|
|
////////////////////////////////////////
|
|
////////////////////////////////////////
|
|
////////////////////////////////////////
|
|
/**
|
|
* Function Return
|
|
*
|
|
* @abstract Main Function Return
|
|
*/ return /*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
|
|
className: "relative w-full max-w-2xl flex-col items-start",
|
|
children: [
|
|
loading && /*#__PURE__*/ jsx_runtime_.jsx(LoadingBlock/* default */.Z, {}),
|
|
!user && /*#__PURE__*/ (0,jsx_runtime_.jsxs)((external_react_default()).Fragment, {
|
|
children: [
|
|
/*#__PURE__*/ jsx_runtime_.jsx("hr", {
|
|
className: "opacity-0"
|
|
}),
|
|
/*#__PURE__*/ jsx_runtime_.jsx(SocialLogin/* default */.Z, {
|
|
user: null,
|
|
userType: "admin",
|
|
setLoading: setLoading
|
|
}),
|
|
/*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
|
|
className: "w-full justify-center relative",
|
|
children: [
|
|
/*#__PURE__*/ jsx_runtime_.jsx("span", {
|
|
className: "bg-white dark:bg-slate-800 px-3 relative z-10",
|
|
children: "OR"
|
|
}),
|
|
/*#__PURE__*/ jsx_runtime_.jsx("hr", {
|
|
className: "absolute"
|
|
})
|
|
]
|
|
})
|
|
]
|
|
}),
|
|
/*#__PURE__*/ (0,jsx_runtime_.jsxs)("form", {
|
|
className: "w-full flex flex-col items-start gap-4 relative",
|
|
onSubmit: (e)=>{
|
|
e.preventDefault();
|
|
submitNewUserForm({
|
|
e,
|
|
setLoading,
|
|
user,
|
|
image,
|
|
query
|
|
});
|
|
},
|
|
children: [
|
|
alert && /*#__PURE__*/ jsx_runtime_.jsx(FormAlertBlock/* default */.Z, {
|
|
message: alert
|
|
}),
|
|
/*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
|
|
className: "flex flex-col items-start gap-0.5 w-full",
|
|
children: [
|
|
/*#__PURE__*/ jsx_runtime_.jsx("label", {
|
|
htmlFor: "first_name",
|
|
children: "First Name"
|
|
}),
|
|
/*#__PURE__*/ jsx_runtime_.jsx("input", {
|
|
type: "text",
|
|
name: "first_name",
|
|
id: "first_name",
|
|
placeholder: "First Name",
|
|
autoComplete: "given-name",
|
|
onInput: (e)=>{
|
|
/** @type {HTMLInputElement} */ // @ts-ignore
|
|
const inputEl = e.target;
|
|
if (inputEl.value.match(/./)) {
|
|
inputEl.classList.remove("warning");
|
|
setAlert(null);
|
|
} else {
|
|
inputEl.classList.add("warning");
|
|
}
|
|
},
|
|
defaultValue: user ? user.first_name : "",
|
|
required: true
|
|
})
|
|
]
|
|
}),
|
|
/*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
|
|
className: "flex flex-col items-start gap-0.5 w-full",
|
|
children: [
|
|
/*#__PURE__*/ jsx_runtime_.jsx("label", {
|
|
htmlFor: "last_name",
|
|
children: "Last Name"
|
|
}),
|
|
/*#__PURE__*/ jsx_runtime_.jsx("input", {
|
|
type: "text",
|
|
name: "last_name",
|
|
id: "last_name",
|
|
placeholder: "Last Name",
|
|
autoComplete: "family-name",
|
|
onInput: (e)=>{
|
|
/** @type {HTMLInputElement} */ // @ts-ignore
|
|
const inputEl = e.target;
|
|
if (inputEl.value.match(/./)) {
|
|
inputEl.classList.remove("warning");
|
|
setAlert(null);
|
|
} else {
|
|
inputEl.classList.add("warning");
|
|
}
|
|
},
|
|
defaultValue: user ? user.last_name : "",
|
|
required: true
|
|
})
|
|
]
|
|
}),
|
|
/*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
|
|
className: "flex flex-col items-start gap-0.5 w-full",
|
|
children: [
|
|
/*#__PURE__*/ jsx_runtime_.jsx("label", {
|
|
htmlFor: "username",
|
|
children: "Username"
|
|
}),
|
|
/*#__PURE__*/ jsx_runtime_.jsx("input", {
|
|
type: "text",
|
|
name: "username",
|
|
id: "username",
|
|
placeholder: "Username",
|
|
autoComplete: "username",
|
|
onInput: (e)=>{
|
|
/** @type {HTMLInputElement} */ // @ts-ignore
|
|
const inputEl = e.target;
|
|
if (inputEl.value.match(/./)) {
|
|
inputEl.classList.remove("warning");
|
|
setAlert(null);
|
|
} else {
|
|
inputEl.classList.add("warning");
|
|
}
|
|
window.clearTimeout(timeout);
|
|
timeout = setTimeout(()=>{
|
|
(0,fetchApi/* default */.Z)(`/api/checkDuplicateData?type=username&value=${inputEl.value}&tableName=users`).then((res)=>{
|
|
console.log(res);
|
|
if (res?.result) {
|
|
setAlert("Username Already Exists");
|
|
inputEl.classList.add("warning");
|
|
} else {
|
|
setAlert(null);
|
|
inputEl.classList.remove("warning");
|
|
}
|
|
});
|
|
}, 300);
|
|
},
|
|
defaultValue: user ? user.username : "",
|
|
required: user ? false : true,
|
|
readOnly: user ? true : false
|
|
})
|
|
]
|
|
}),
|
|
/*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
|
|
className: "flex flex-col items-start gap-0.5 w-full",
|
|
children: [
|
|
/*#__PURE__*/ jsx_runtime_.jsx("label", {
|
|
htmlFor: "email_address",
|
|
children: "Email Address"
|
|
}),
|
|
/*#__PURE__*/ jsx_runtime_.jsx("input", {
|
|
type: "email",
|
|
name: "email_address",
|
|
id: "email_address",
|
|
placeholder: "Email Address",
|
|
autoComplete: "email",
|
|
onInput: (e)=>{
|
|
/** @type {HTMLInputElement} */ // @ts-ignore
|
|
const inputEl = e.target;
|
|
window.clearTimeout(timeout);
|
|
timeout = setTimeout(()=>{
|
|
(0,fetchApi/* default */.Z)(`/api/checkDuplicateData?type=email&value=${inputEl.value}&tableName=users`).then((res)=>{
|
|
console.log(res);
|
|
if (res?.result) {
|
|
setAlert("Email Already Exists");
|
|
inputEl.classList.add("warning");
|
|
} else {
|
|
setAlert(null);
|
|
inputEl.classList.remove("warning");
|
|
}
|
|
});
|
|
}, 300);
|
|
},
|
|
defaultValue: defaultEmail,
|
|
required: true,
|
|
readOnly: user ? true : false
|
|
})
|
|
]
|
|
}),
|
|
!user && /*#__PURE__*/ (0,jsx_runtime_.jsxs)((external_react_default()).Fragment, {
|
|
children: [
|
|
/*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
|
|
className: "flex flex-col items-start gap-0.5 w-full",
|
|
children: [
|
|
/*#__PURE__*/ jsx_runtime_.jsx("label", {
|
|
htmlFor: "password",
|
|
children: "Password"
|
|
}),
|
|
/*#__PURE__*/ jsx_runtime_.jsx("input", {
|
|
type: "password",
|
|
name: "password",
|
|
id: "password",
|
|
placeholder: "Password",
|
|
required: true
|
|
})
|
|
]
|
|
}),
|
|
/*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
|
|
className: "flex flex-col items-start gap-0.5 w-full",
|
|
children: [
|
|
/*#__PURE__*/ jsx_runtime_.jsx("label", {
|
|
htmlFor: "confirm_password",
|
|
children: "Confirm Password"
|
|
}),
|
|
/*#__PURE__*/ jsx_runtime_.jsx("input", {
|
|
type: "password",
|
|
name: "confirm_password",
|
|
id: "confirm_password",
|
|
placeholder: "Confirm Password",
|
|
onInput: (e)=>{
|
|
/** @type {HTMLInputElement} */ // @ts-ignore
|
|
const inputEl = e.target;
|
|
let passwordInput = inputEl.closest("form")?.["password"].value;
|
|
let passwordRepeatInput = inputEl.value;
|
|
if (passwordInput === passwordRepeatInput) {
|
|
inputEl.classList.remove("warning");
|
|
} else {
|
|
inputEl.classList.add("warning");
|
|
}
|
|
},
|
|
required: true
|
|
})
|
|
]
|
|
}),
|
|
/*#__PURE__*/ (0,jsx_runtime_.jsxs)("span", {
|
|
className: "text-sm",
|
|
children: [
|
|
'By clicking "Create Account" you agree to our',
|
|
" ",
|
|
/*#__PURE__*/ jsx_runtime_.jsx("a", {
|
|
href: "/terms",
|
|
target: "_blank",
|
|
className: "font-bold",
|
|
children: "Terms and Conditions"
|
|
})
|
|
]
|
|
})
|
|
]
|
|
}),
|
|
/*#__PURE__*/ jsx_runtime_.jsx("button", {
|
|
type: "submit",
|
|
className: "w-full",
|
|
children: user ? /*#__PURE__*/ jsx_runtime_.jsx("span", {
|
|
children: "Update Account Info"
|
|
}) : /*#__PURE__*/ jsx_runtime_.jsx("span", {
|
|
children: "Create Account"
|
|
})
|
|
}),
|
|
!user && /*#__PURE__*/ jsx_runtime_.jsx((external_react_default()).Fragment, {
|
|
children: /*#__PURE__*/ (0,jsx_runtime_.jsxs)("span", {
|
|
className: "text-sm",
|
|
children: [
|
|
"Already Have an Account?",
|
|
" ",
|
|
/*#__PURE__*/ jsx_runtime_.jsx("a", {
|
|
href: "/login",
|
|
className: "font-bold",
|
|
children: "Login"
|
|
})
|
|
]
|
|
})
|
|
})
|
|
]
|
|
})
|
|
]
|
|
});
|
|
////////////////////////////////////////
|
|
////////////////////////////////////////
|
|
////////////////////////////////////////
|
|
} /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */
|
|
|
|
|
|
/***/ })
|
|
|
|
};
|
|
; |