refactor code

This commit is contained in:
RaktimaNXG
2024-04-03 20:30:46 +05:30
parent 824b0a5407
commit a2467ef1a6
2 changed files with 49 additions and 47 deletions
+48
View File
@@ -10,6 +10,7 @@ import Parse from "parse";
import ModalUi from "../primitives/ModalUi";
import { useNavigate, useLocation, Outlet } from "react-router-dom";
import { isEnableSubscription } from "../constant/const";
import { useCookies } from "react-cookie";
const HomeLayout = () => {
const navigate = useNavigate();
@@ -24,6 +25,21 @@ const HomeLayout = () => {
const [isTour, setIsTour] = useState(false);
const [tourStatusArr, setTourStatusArr] = useState([]);
const [tourConfigs, setTourConfigs] = useState([]);
const [, setCookie] = useCookies([
"TenantId",
"userDetails",
"userEmail",
"profileImg",
"fev_Icon",
"accesstoken",
`Parse/${localStorage.getItem("parseAppId")}/currentUser`,
"appLogo",
"baseUrl",
"domain",
"parseAppId",
"username",
"main_Domain"
]);
useEffect(() => {
(async () => {
@@ -43,8 +59,40 @@ const HomeLayout = () => {
setIsUserValid(false);
}
})();
saveCookies();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
//function to use save data in cookies storage
const saveCookies = () => {
setCookie("TenantId", localStorage.getItem("TenantId"), { secure: true });
setCookie("userDetails", localStorage.getItem("userDetails"), {
secure: true
});
setCookie("userEmail", localStorage.getItem("userEmail"), { secure: true });
setCookie("profileImg", localStorage.getItem("profileImg"), {
secure: true
});
setCookie("fev_Icon", localStorage.getItem("fev_Icon"), { secure: true });
setCookie("accesstoken", localStorage.getItem("accesstoken"), {
secure: true
});
setCookie(
`Parse/${localStorage.getItem("parseAppId")}/currentUser`,
localStorage.getItem(
`Parse/${localStorage.getItem("parseAppId")}/currentUser`
),
{ secure: true }
);
setCookie("appLogo", localStorage.getItem("appLogo"), { secure: true });
setCookie("baseUrl", localStorage.getItem("baseUrl"), { secure: true });
setCookie("domain", localStorage.getItem("domain"), { secure: true });
setCookie("parseAppId", localStorage.getItem("parseAppId"), {
secure: true
});
setCookie("username", localStorage.getItem("username"), { secure: true });
setCookie("main_Domain", window.location.host, { secure: true });
};
async function checkIsSubscribed() {
const currentUser = Parse.User.current();
+1 -47
View File
@@ -6,7 +6,7 @@ import { useNavigate, useParams } from "react-router-dom";
import Title from "../components/Title";
import { useDispatch } from "react-redux";
import { saveTourSteps } from "../redux/reducers/TourStepsReducer";
import { useCookies } from "react-cookie";
const Dashboard = () => {
const navigate = useNavigate();
const dispatch = useDispatch();
@@ -15,25 +15,9 @@ const Dashboard = () => {
const [classnameArray, setclassnameArray] = useState([]);
const [loading, setloading] = useState(false);
const [defaultQuery, setDefaultQuery] = useState("");
const [, setCookie] = useCookies([
"TenantId",
"userDetails",
"userEmail",
"profileImg",
"fev_Icon",
"accesstoken",
`Parse/${localStorage.getItem("parseAppId")}/currentUser`,
"appLogo",
"baseUrl",
"domain",
"parseAppId",
"username",
"main_Domain"
]);
useEffect(() => {
if (localStorage.getItem("accesstoken")) {
saveCookies();
if (id !== undefined) {
getDashboard(id);
} else {
@@ -45,36 +29,6 @@ const Dashboard = () => {
// eslint-disable-next-line
}, [id]);
//function to use save data in cookies storage
const saveCookies = () => {
setCookie("TenantId", localStorage.getItem("TenantId"), { secure: true });
setCookie("userDetails", localStorage.getItem("userDetails"), {
secure: true
});
setCookie("userEmail", localStorage.getItem("userEmail"), { secure: true });
setCookie("profileImg", localStorage.getItem("profileImg"), {
secure: true
});
setCookie("fev_Icon", localStorage.getItem("fev_Icon"), { secure: true });
setCookie("accesstoken", localStorage.getItem("accesstoken"), {
secure: true
});
setCookie(
`Parse/${localStorage.getItem("parseAppId")}/currentUser`,
localStorage.getItem(
`Parse/${localStorage.getItem("parseAppId")}/currentUser`
),
{ secure: true }
);
setCookie("appLogo", localStorage.getItem("appLogo"), { secure: true });
setCookie("baseUrl", localStorage.getItem("baseUrl"), { secure: true });
setCookie("domain", localStorage.getItem("domain"), { secure: true });
setCookie("parseAppId", localStorage.getItem("parseAppId"), {
secure: true
});
setCookie("username", localStorage.getItem("username"), { secure: true });
setCookie("main_Domain", window.location.host, { secure: true });
};
const getDashboard = async (id) => {
setloading(true);
try {