fix: username issue to get details from GetPublicUserNmae cloud function

This commit is contained in:
RaktimaNXG
2024-05-29 18:17:07 +05:30
parent b32c8068ef
commit d85074b127
10 changed files with 366 additions and 193 deletions
+2 -1
View File
@@ -9,4 +9,5 @@ export const modalSubmitBtnColor = "#17a2b8";
export const modalCancelBtnColor = "white";
export const themeColor = "#47a3ad";
export const iconColor = "#686968";
export const isEnableSubscription = process.env.REACT_APP_ENABLE_SUBSCRIPTION;
export const isEnableSubscription = false;
// process.env.REACT_APP_ENABLE_SUBSCRIPTION;
+4 -1
View File
@@ -1578,7 +1578,10 @@ function PdfRequestFiles() {
handleClose={() => {
setIsCompleted((prev) => ({ ...prev, isModal: false }));
}}
reduceWidth={!isCompleted?.message}
reduceWidth={
!isCompleted?.message &&
"md:min-w-[440px] md:max-w-[400px]"
}
>
<div style={{ height: "100%", padding: 20 }}>
{isCompleted?.message ? (
+59 -34
View File
@@ -1,4 +1,4 @@
import React, { useState, useEffect } from "react";
import React, { useState, useEffect, useRef } from "react";
import { Navigate, useNavigate } from "react-router-dom";
import Parse from "parse";
import { SaveFileSize } from "../constant/saveFileSize";
@@ -28,8 +28,9 @@ function UserProfile() {
const [isDisableDocId, setIsDisableDocId] = useState(false);
const [isSubscribe, setIsSubscribe] = useState(false);
const [publicUserName, setPublicUserName] = useState(
(extendUser && extendUser?.[0]?.UserName) || ""
extendUser && extendUser?.[0]?.UserName
);
const previousStateValueRef = useRef(publicUserName);
const [company, setCompany] = useState(
extendUser && extendUser?.[0]?.Company
);
@@ -81,8 +82,8 @@ function UserProfile() {
const handleCheckPublicUserName = async () => {
try {
const res = await Parse.Cloud.run("getPublicUserName", {
userName: publicUserName
const res = await Parse.Cloud.run("getpublicusername", {
username: publicUserName
});
if (res) {
setIsLoader(false);
@@ -98,15 +99,19 @@ function UserProfile() {
};
const handleSubmit = async (e) => {
e.preventDefault();
setIsLoader(true);
let phn = Phone;
const res = await handleCheckPublicUserName();
let phn = Phone,
res;
if (previousStateValueRef.current !== publicUserName) {
res = await handleCheckPublicUserName();
}
if (!res) {
setIsLoader(true);
try {
const tour = Parse.Object.extend("_User");
const query = new Parse.Query(tour);
const userQuery = Parse.Object.extend("_User");
const query = new Parse.Query(userQuery);
await query.get(UserProfile.objectId).then((object) => {
object.set("name", name);
object.set("ProfilePic", Image);
@@ -148,15 +153,26 @@ function UserProfile() {
const extClass = localStorage.getItem("extended_class");
const extData = JSON.parse(localStorage.getItem("Extand_Class"));
const ExtUserId = extData[0].objectId;
let body;
if (publicUserName) {
body = {
Phone: obj.Phone,
Name: obj.Name,
HeaderDocId: isDisableDocId,
JobTitle: jobTitle,
Company: company,
UserName: publicUserName
};
} else {
body = {
Phone: obj.Phone,
Name: obj.Name,
HeaderDocId: isDisableDocId,
JobTitle: jobTitle,
Company: company
};
}
const body = {
Phone: obj.Phone,
Name: obj.Name,
HeaderDocId: isDisableDocId,
JobTitle: jobTitle,
Company: company,
UserName: publicUserName
};
await axios.put(
parseBaseUrl + "classes/" + extClass + "/" + ExtUserId,
body,
@@ -267,7 +283,15 @@ function UserProfile() {
alert("OTP sent on you email");
};
const handlePublicUrl = (e) => {
setPublicUserName(e.target.value);
const value = e.target.value;
if (value.length > 6 && !isSubscribe) {
setUserNameError("Please upgrade to allow more than 6 characters.");
setTimeout(() => {
setUserNameError("");
}, 2000);
} else {
setPublicUserName(e.target.value);
}
};
return (
<React.Fragment>
@@ -291,10 +315,9 @@ function UserProfile() {
</div>
) : (
<div className="flex justify-center items-center w-full relative">
{/* <Alert type={alertMsg.type}>{alertMsg.message}</Alert> */}
{userNameError && (
<div
className={`z-[1000] fixed top-20 transform border-[1px] text-sm border-[#f0a8a8] bg-[#f4bebe] text-[#c42121] rounded py-[.75rem] px-[1.25rem]`}
className={`z-[1000] fixed top-[50%] transform border-[1px] text-sm border-[#f0a8a8] bg-[#f4bebe] text-[#c42121] rounded py-[.75rem] px-[1.25rem]`}
>
{userNameError}
</div>
@@ -426,20 +449,22 @@ function UserProfile() {
)}
</span>
</li>
<li className="flex justify-between items-center border-t-[1px] border-gray-300 py-2 break-all">
<span className="font-semibold">Public profile:</span>
<div className="flex items-center">
<span>opensign.me/</span>
{!isEnableSubscription && (
<li className="flex justify-between items-center border-t-[1px] border-gray-300 py-2 break-all">
<span className="font-semibold">Public profile:</span>
<div className="flex items-center">
<span>opensign.me/</span>
<input
onChange={handlePublicUrl}
value={publicUserName}
disabled={!editmode}
placeholder="enter user name"
className="border-[1px] border-gray-200 rounded-[3px]"
/>
</div>
</li>
<input
onChange={handlePublicUrl}
value={publicUserName}
disabled={!editmode}
placeholder="enter user name"
className="border-[1px] border-gray-200 rounded-[3px]"
/>
</div>
</li>
)}
<li className="border-y-[1px] border-gray-300 break-all">
<div className="flex justify-between items-center py-2">
+227 -117
View File
@@ -4,14 +4,18 @@ import { useNavigate } from "react-router-dom";
import axios from "axios";
import ModalUi from "./ModalUi";
import AddSigner from "../components/AddSigner";
import { modalSubmitBtnColor, modalCancelBtnColor } from "../constant/const";
import {
modalSubmitBtnColor,
modalCancelBtnColor,
isEnableSubscription
} from "../constant/const";
import Alert from "./Alert";
import Tooltip from "./Tooltip";
import { RWebShare } from "react-web-share";
import Tour from "reactour";
import Parse from "parse";
import { saveAs } from "file-saver";
import { replaceMailVaribles } from "../constant/Utils";
import { copytoData, replaceMailVaribles } from "../constant/Utils";
import Confetti from "react-confetti";
import EditorToolbar, {
module1,
@@ -48,7 +52,9 @@ const ReportTable = (props) => {
const [role, setRole] = useState([]);
const [selectedPublicRole, setSelectedPublicRole] = useState("");
const [isCelebration, setIsCelebration] = useState(false);
const [isPublic, setIsPublic] = useState({});
const [isPublicProfile, setIsPublicProfile] = useState({});
const [publicUserName, setIsPublicUserName] = useState("raktima");
const [isViewShare, setIsViewShare] = useState({});
const startIndex = (currentPage - 1) * props.docPerPage;
const { isMoreDocs, setIsNextRecord } = props;
@@ -235,17 +241,6 @@ const ReportTable = (props) => {
setIsResendMail({ [item.objectId]: true });
} else if (act.action === "bulksend") {
handleBulkSend(item);
} else if (act.action === "public") {
const getRole = [];
const getPlaceholder = item.Placeholders;
getPlaceholder.map((data) => {
getRole.push(data.Role);
});
if (getRole.length === 1) {
setSelectedPublicRole(getRole[0]);
}
setRole(getRole);
setIsMakePublic({ [item.objectId]: true });
}
};
// Get current list
@@ -318,6 +313,9 @@ const ReportTable = (props) => {
setIsRevoke({});
setIsDeleteModal({});
setIsMakePublic({});
setSelectedPublicRole("");
setIsPublic({});
setIsPublicProfile({});
};
const handleShare = (item) => {
@@ -711,50 +709,35 @@ const ReportTable = (props) => {
if (selectedPublicRole) {
setActLoader({ [item.objectId]: true });
setIsMakePublic(false);
let params = {
templateId: item.objectId
};
let url = `${localStorage.getItem(
"baseUrl"
)}functions/createPublicTemplate/`;
const headers = {
"Content-Type": "application/json",
"X-Parse-Application-Id": localStorage.getItem("parseAppId"),
sessionToken: localStorage.getItem("accesstoken")
};
try {
const res = await axios.post(url, params, { headers: headers });
if (res.data.result.status === "success") {
const data = {
PublicRole: [selectedPublicRole]
};
const res = await axios.put(
`${localStorage.getItem("baseUrl")}classes/contracts_Template/${
item.objectId
}`,
data,
{
headers: {
"Content-Type": "application/json",
"X-Parse-Application-Id": localStorage.getItem("parseAppId"),
"X-Parse-Session-Token": localStorage.getItem("accesstoken")
}
}
);
if (res) {
setIsAlert(true);
const res = await Parse.Cloud.run("createpublictemplate", {
templateid: item.objectId,
ispublic: isPublic[item.objectId],
publicrole: [selectedPublicRole]
});
if (res.status === "success") {
setIsAlert(true);
setTimeout(() => setIsAlert(false), 1500);
if (isPublic[item.objectId]) {
setAlertMsg({
type: "success",
message: "You have successfully made the template public."
});
setTimeout(() => setIsAlert(false), 1500);
setIsCelebration(true);
setTimeout(() => {
setIsCelebration(false);
}, 5000);
setIsPublicProfile({ [item.objectId]: isPublic[item.objectId] });
} else {
setAlertMsg({
type: "success",
message: "You have successfully made the template private."
});
setSelectedPublicRole("");
setActLoader({});
}
setActLoader({});
}
} catch (e) {
console.log("save public template error", e);
@@ -768,10 +751,50 @@ const ReportTable = (props) => {
setTimeout(() => setIsAlert(false), 1500);
}
};
const handleViewSigners = (item) => {
setIsViewShare({ [item.objectId]: true });
};
const handlePublicChange = async (e, item) => {
const getPlaceholder = item?.Placeholders;
if (getPlaceholder && getPlaceholder.length > 0) {
let extendUser = JSON.parse(localStorage.getItem("Extand_Class"));
const userName = extendUser[0]?.UserName;
setIsPublicUserName(extendUser[0]?.UserName);
if (userName) {
setIsPublic({ [item.objectId]: e.target.checked });
const getRole = [];
getPlaceholder.map((data) => {
getRole.push(data.Role);
});
if (getRole.length === 1) {
setSelectedPublicRole(getRole[0]);
}
setRole(getRole);
setIsMakePublic({ [item.objectId]: true });
} else {
setIsPublicProfile({ [item.objectId]: true });
}
} else {
setIsAlert(true);
setAlertMsg({
type: "danger",
message: "Please assign at least one role to make this template public."
});
setTimeout(() => setIsAlert(false), 3000);
}
};
const copytoProfileLink = () => {
const url = `https://opensign.me/${publicUserName}`;
copytoData(url);
setIsAlert(true);
setAlertMsg({
type: "success",
message: "Copied."
});
setTimeout(() => setIsAlert(false), 1500);
};
return (
<div className="relative">
{Object.keys(actLoader)?.length > 0 && (
@@ -834,6 +857,9 @@ const ReportTable = (props) => {
{props.actions?.length > 0 && (
<th className="px-4 py-2 font-thin">Action</th>
)}
{props.ReportName === "Templates" && !isEnableSubscription && (
<th className="px-4 py-2 font-thin">Public</th>
)}
</tr>
</thead>
<tbody className="text-[12px]">
@@ -1272,84 +1298,168 @@ const ReportTable = (props) => {
</div>
</ModalUi>
)}
{isMakePublic[item.objectId] && (
<ModalUi
isOpen
title={"Make template public"}
handleClose={() => {
setIsMakePublic({});
}}
>
<div className="m-[20px]">
<div className="font-normal text-black">
<p className="text-lg">
{" "}
Are you sure you want to make this template
public?
</p>
<div className="flex mt-2 gap-2 md:items-center">
<p className="text-[15px]">Public role : </p>
{role.length > 1 ? (
<select
className="w-[60%] md:w-[70%] border-[1px] border-gray-200 rounded-sm p-[2px]"
name="textvalidate"
value={selectedPublicRole}
onChange={(e) =>
setSelectedPublicRole(e.target.value)
}
>
<option
disabled
style={{ fontSize: "13px" }}
value=""
>
Select...
</option>
{role.map((data, ind) => {
return (
</td>
{!isEnableSubscription && (
<td className=" pl-[20px] py-2 ">
{props.ReportName === "Templates" && (
<div className=" flex flex-row-">
<label
className={
"cursor-pointer relative inline-flex items-center mb-0"
}
>
<input
checked={
(isPublic && isPublic[item.objectId]) ||
item?.IsPublic ||
false
}
onChange={(e) => handlePublicChange(e, item)}
type="checkbox"
value=""
className="sr-only peer"
/>
<div className="w-9 h-5 bg-gray-200 peer-focus:outline-none peer-focus:ring-1 peer-focus:ring-black rounded-full peer dark:bg-gray-700 peer-checked:after:translate-x-full rtl:peer-checked:after:-translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:start-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-4 after:w-4 after:transition-all dark:border-black peer-checked:bg-blue-600"></div>
</label>
</div>
)}
{isMakePublic[item.objectId] && (
<ModalUi
isOpen
title={"Make template public"}
handleClose={() => {
setIsMakePublic({});
setSelectedPublicRole("");
setIsPublic({});
}}
>
<div className="m-[20px]">
<div className="font-normal text-black">
<p className="text-lg">
{" "}
{isPublic[item.objectId]
? `Are you sure you want to make this template
public ?`
: `Are you sure you want to make this template
private ?`}
</p>
{isPublic[item.objectId] && (
<div className="flex mt-2 gap-2 md:items-center">
<p className="text-[15px]">
Public role :{" "}
</p>
{role.length > 1 ? (
<select
className="w-[60%] md:w-[70%] border-[1px] border-gray-200 rounded-sm p-[2px]"
name="textvalidate"
value={selectedPublicRole}
onChange={(e) =>
setSelectedPublicRole(
e.target.value
)
}
>
<option
disabled
style={{ fontSize: "13px" }}
key={ind}
value={data}
value=""
>
{data}
Select...
</option>
);
})}
</select>
) : (
<div className="w-[60%] md:w-[70%] border-[1px] border-gray-200 rounded-sm p-[2px]">
{role}
{role.map((data, ind) => {
return (
<option
style={{ fontSize: "13px" }}
key={ind}
value={data}
>
{data}
</option>
);
})}
</select>
) : (
<div className="w-[60%] md:w-[70%] border-[1px] border-gray-200 rounded-sm p-[2px]">
{role}
</div>
)}
</div>
)}
</div>
</div>
<hr className="bg-[#ccc] mt-2 " />
<div className="flex items-center mt-3 gap-2 text-white">
<button
onClick={() => handlePublicTemplate(item)}
className="px-4 py-1.5 text-white rounded shadow-md text-center focus:outline-none "
style={{
backgroundColor: modalSubmitBtnColor
}}
>
Submit
</button>
<button
onClick={handleClose}
className="px-4 py-1.5 text-black border-[1px] border-[#ccc] shadow-md rounded focus:outline-none"
style={{
backgroundColor: modalCancelBtnColor
}}
>
No
</button>
<hr className="bg-[#ccc] mt-2 " />
<div className="flex items-center mt-3 gap-2 text-white">
<button
onClick={() => handlePublicTemplate(item)}
className="px-4 py-1.5 text-white rounded shadow-md text-center focus:outline-none "
style={{
backgroundColor: modalSubmitBtnColor
}}
>
Submit
</button>
<button
onClick={handleClose}
className="px-4 py-1.5 text-black border-[1px] border-[#ccc] shadow-md rounded focus:outline-none"
style={{
backgroundColor: modalCancelBtnColor
}}
>
No
</button>
</div>
</div>
</div>
</ModalUi>
)}
</td>
</ModalUi>
)}
{isPublicProfile[item.objectId] && (
<ModalUi
isOpen
title={"Public url"}
handleClose={() => {
setIsPublicProfile({});
}}
reduceWidth={"md:min-w-[440px] md:max-w-[400px]"}
>
<div className="m-[20px]">
{publicUserName ? (
<div className="font-normal text-black">
<p>
Heres your public URL. Copy or share it
with the signer, and you will be able to
see all your publicly set templates.
</p>
<div className=" flex items-center gap-5 mt-2 p-[2px] w-[75%]">
<span className="font-bold">
Public Url :{" "}
</span>
<span
onClick={() => copytoProfileLink()}
className="underline underline-offset-2 cursor-pointer"
>{`https://opensign.me/${publicUserName}`}</span>
</div>
</div>
) : (
<div className="font-normal text-black">
<p>
Please add your public URL, and you will
be able to make a public template.
</p>
<button
className="px-4 py-1.5 mt-3 text-white rounded shadow-md text-center focus:outline-none "
style={{
backgroundColor: modalSubmitBtnColor
}}
onClick={() => navigate("/profile")}
>
Add
</button>
</div>
)}
</div>
</ModalUi>
)}
</td>
)}
</tr>
)
)}
+1 -3
View File
@@ -19,9 +19,7 @@ const ModalUi = ({
<div className="fixed z-[999] top-0 left-0 w-[100%] h-[100%] bg-black bg-opacity-[75%]">
<div
className={`${
reduceWidth
? "md:min-w-[440px] md:max-w-[400px]"
: "md:min-w-[500px]"
reduceWidth || "md:min-w-[500px]"
} fixed z-[1000] top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 text-sm bg-white rounded shadow-md max-h-90 min-w-[90%] overflow-y-auto hide-scrollbar `}
>
{showHeader && (
+5 -2
View File
@@ -40,6 +40,8 @@ import { getSignedUrl } from './parsefunction/getSignedUrl.js';
import createBatchDocs from './parsefunction/createBatchDocs.js';
import linkContactToDoc from './parsefunction/linkContactToDoc.js';
import CreatePublicTemplate from './parsefunction/CreatePublicTemplate.js';
import GetPublicUserName from './parsefunction/GetPublicUserName.js';
import GetPublicTemplate from './parsefunction/GetPublicTemplate.js';
// This afterSave function triggers after an object is added or updated in the specified class, allowing for post-processing logic.
Parse.Cloud.afterSave('contracts_Document', DocumentAftersave);
@@ -89,5 +91,6 @@ Parse.Cloud.define('encryptedpdf', encryptedpdf);
Parse.Cloud.define('getsignedurl', getSignedUrl);
Parse.Cloud.define('batchdocuments', createBatchDocs);
Parse.Cloud.define('linkcontacttodoc', linkContactToDoc);
Parse.Cloud.define('createPublicTemplate', CreatePublicTemplate);
Parse.Cloud.define('getPublicUserName', GetPublicUserName);
Parse.Cloud.define('createpublictemplate', CreatePublicTemplate);
Parse.Cloud.define('getpublicusername', GetPublicUserName);
Parse.Cloud.define('getpublictemplate', GetPublicTemplate);
@@ -1,39 +1,42 @@
import axios from 'axios';
export default async function CreatePublicTemplate(request) {
const templateId = request.params.templateId;
const serverUrl = process.env.SERVER_URL;
const appId = process.env.APP_ID;
const templateid = request.params.templateid;
const ispublic = request.params.ispublic;
const publicrole = request.params.publicrole;
try {
const userRes = await axios.get(serverUrl + '/users/me', {
headers: {
'X-Parse-Application-Id': appId,
'X-Parse-Session-Token': request.headers['sessiontoken'],
},
});
const userId = userRes.data && userRes.data.objectId;
if (userId) {
const Query = new Parse.Query('contracts_Template');
Query.equalTo('CreatedBy', {
__type: 'Pointer',
className: '_User',
objectId: userId,
});
const updateACL = await Query.get(templateId, { useMasterKey: true });
const newACL = new Parse.ACL();
newACL.setPublicReadAccess(true);
newACL.setPublicWriteAccess(true);
updateACL.setACL(newACL);
updateACL.save(null, { useMasterKey: true });
return {
status: 'success',
};
console.log('session token', request);
if (!request?.user) {
throw new Parse.Error(Parse.Error.INVALID_SESSION_TOKEN, 'User is not authenticated.');
} else {
const userId = request?.user && request?.user?.id;
if (userId) {
const updateTemplate = new Parse.Object('contracts_Template');
updateTemplate.id = templateid;
if (ispublic) {
updateTemplate.set('PublicRole', publicrole);
}
updateTemplate.set('IsPublic', ispublic);
const Acl = new Parse.ACL();
if (ispublic) {
Acl.setPublicReadAccess(true);
}
Acl.setReadAccess(userId, true);
Acl.setWriteAccess(userId, true);
updateTemplate.setACL(Acl);
const savedObject = await updateTemplate.save(null, { useMasterKey: true });
const res = savedObject.toJSON();
if (res) {
return {
status: 'success',
};
}
} else {
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'User does not exist.');
}
}
} catch (err) {
if (err.code == 209) {
return { error: 'Invalid session token' };
} else {
return { error: "You don't have access of this document!" };
}
const code = err.code || 400;
const msg = err.message;
const error = new Parse.Error(code, msg);
throw error;
}
}
@@ -0,0 +1,29 @@
async function GetPublicTemplate(request) {
try {
const username = request.params.username;
if (username) {
const extUserQuery = new Parse.Query('contracts_Users');
extUserQuery.equalTo('UserName', username);
const res = await extUserQuery.first({ useMasterKey: true });
const userId = res.get('UserId').id;
if (userId) {
const templatQuery = new Parse.Query('contracts_Template');
templatQuery.equalTo('CreatedBy', {
__type: 'Pointer',
className: '_User',
objectId: userId,
});
templatQuery.equalTo('IsPublic', true);
const getTemplate = await templatQuery.find({ useMasterKey: true });
return getTemplate;
}
return { error: "You don't have access of this document!" };
} else {
return { error: 'Please provide username!' };
}
} catch (err) {
console.log('error', err);
return { error: "You don't have access of this document!" };
}
}
export default GetPublicTemplate;
@@ -1,8 +1,8 @@
async function GetPublicUserName(request) {
try {
const userName = request.params.userName;
const username = request.params.username;
const userQuery = new Parse.Query('contracts_Users');
userQuery.equalTo('UserName', userName);
userQuery.equalTo('UserName', username);
const res = await userQuery.first({ useMasterKey: true });
return res;
} catch (err) {
@@ -334,6 +334,7 @@ export default function reportJson(id, userId) {
'Signers.Email',
'Signers.Phone',
'Placeholders',
'IsPublic',
],
};
default: