Skip to content

Commit

Permalink
feat: save release version and remove saved product if the release ch…
Browse files Browse the repository at this point in the history
…anges (#899)

* 1.0.0

* feat: remove saved product if release version changes
  • Loading branch information
albertfolch-redeemeum authored Oct 25, 2023
1 parent 1a42d54 commit cf9aa40
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 64 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "interface",
"homepage": ".",
"version": "0.1.0",
"version": "1.0.0",
"private": true,
"repository": {
"type": "git",
Expand Down
15 changes: 11 additions & 4 deletions src/components/product/utils/useInitialValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import useProductByUuid, {
ReturnUseProductByUuid
} from "lib/utils/hooks/product/useProductByUuid";
import { useCurrentSellers } from "lib/utils/hooks/useCurrentSellers";
import { didReleaseVersionChange } from "lib/utils/release";
import { useCoreSDK } from "lib/utils/useCoreSdk";
import uniqBy from "lodash.uniqby";
import { getDisputePeriodDurationFromSubgraphInDays } from "pages/create-product/utils/helpers";
Expand Down Expand Up @@ -70,10 +71,16 @@ export function useInitialValues() {
}),
[config.envConfig]
);
const initialValues = useMemo(
() => getItemFromStorage<CreateProductForm | null>(MAIN_KEY, null),
[]
);
const initialValues = useMemo(() => {
const savedProduct = getItemFromStorage<CreateProductForm | null>(
MAIN_KEY,
null
);
if (didReleaseVersionChange()) {
return null;
}
return savedProduct;
}, []);

const { data: product } = useProductByUuid(sellerId, fromProductUuid, {
enabled: !!fromProductUuid && !!sellerId
Expand Down
5 changes: 3 additions & 2 deletions src/lib/utils/hooks/useLocalStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export type GetItemFromStorageKey =
| "isConnectWalletFromCommit"
| "showCookies"
| "showCookiesDrCenter"
| "release-version"
| CreateProductImageProductImages
| CreateProductImageCreateYourProfileLogo;

Expand All @@ -43,7 +44,7 @@ export function getItemFromStorage<T>(
}
}

export function saveItemInStorage<T>(key: string, value: T) {
export function saveItemInStorage<T>(key: GetItemFromStorageKey, value: T) {
if (typeof window !== "undefined") {
try {
window.localStorage.setItem(key, JSON.stringify(value));
Expand All @@ -54,7 +55,7 @@ export function saveItemInStorage<T>(key: string, value: T) {
}
}

export function removeItemInStorage(key: string) {
export function removeItemInStorage(key: GetItemFromStorageKey) {
if (typeof window !== "undefined") {
try {
Object.keys(localStorage)
Expand Down
16 changes: 16 additions & 0 deletions src/lib/utils/release.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { CONFIG } from "lib/config";

import { getItemFromStorage, saveItemInStorage } from "./hooks/useLocalStorage";

export const didReleaseVersionChange = (): boolean => {
const releaseVersion = getItemFromStorage("release-version", undefined);
const currentReleaseVersion = CONFIG.releaseTag;
return releaseVersion !== currentReleaseVersion;
};

export const saveCurrentReleaseVersion = (): void => {
const currentReleaseVersion = CONFIG.releaseTag;
if (currentReleaseVersion) {
saveItemInStorage("release-version", currentReleaseVersion);
}
};
19 changes: 18 additions & 1 deletion src/router/AppRouter.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,35 @@
import { useConfigContext } from "components/config/ConfigContext";
import { removeItemInStorage } from "lib/utils/hooks/useLocalStorage";
import {
didReleaseVersionChange,
saveCurrentReleaseVersion
} from "lib/utils/release";
import { queryClient } from "queryClient";
import { useEffect } from "react";
import { HashRouter, Route } from "react-router-dom";

import SentryProvider from "../components/SentryProvider";
import ScrollToTop from "../components/utils/Scroll";
import routes, { IRoutes } from "./routes";
import routes from "./routes";
import SuspenseRoute from "./SuspenseRoute";
import { IRoutes } from "./types";

const useHandleRelease = () => {
useEffect(() => {
if (didReleaseVersionChange()) {
removeItemInStorage("create-product");
}

saveCurrentReleaseVersion();
}, []);
};

export default function AppRouter() {
const { config } = useConfigContext();
useEffect(() => {
queryClient.invalidateQueries();
}, [config.envConfig.configId]);
useHandleRelease();
return (
<HashRouter>
<ScrollToTop />
Expand Down
20 changes: 2 additions & 18 deletions src/router/dappRoutes.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React, { lazy } from "react";
import { RouteProps } from "react-router";
import { lazy } from "react";

import {
BosonRoutes,
OffersRoutes,
ProductRoutes,
SellerCenterRoutes
} from "../lib/routing/routes";
import { IRoutes } from "./types";
const AboutPage = lazy(() => import("../pages/about/AboutPage"));
const ChatPage = lazy(() => import("../pages/chat/Chat"));
const CustomStorePage = lazy(
Expand Down Expand Up @@ -70,22 +70,6 @@ export const UserRoles = {
Seller: "Seller",
DisputeResolver: "DisputeResolver"
} as const;
export interface IRoutes extends RouteProps {
component:
| React.ComponentType<any> // eslint-disable-line
| React.LazyExoticComponent<React.ComponentType<any>>; // eslint-disable-line
role: Array<string | null>;
componentProps?: {
[key: string]: string;
};
app?: {
withLayout?: boolean;
withFooter?: boolean;
fluidHeader?: boolean;
withBosonStyles?: boolean;
withBanner?: boolean;
};
}

export default [
{
Expand Down
20 changes: 2 additions & 18 deletions src/router/drCenterRoutes.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { lazy } from "react";
import { RouteProps } from "react-router";
import { lazy } from "react";

import { DrCenterRoutes } from "../lib/routing/drCenterRoutes";
import { IRoutes } from "./types";

const ChatPage = lazy(() => import("../pages/chat/Chat"));
const DisputeCenterPage = lazy(
Expand Down Expand Up @@ -38,22 +38,6 @@ export const UserRoles = {
Seller: "Seller",
DisputeResolver: "DisputeResolver"
} as const;
export interface IRoutes extends RouteProps {
component:
| React.ComponentType<any> // eslint-disable-line
| React.LazyExoticComponent<React.ComponentType<any>>; // eslint-disable-line
role: Array<string | null>;
componentProps?: {
[key: string]: string;
};
app?: {
withLayout?: boolean;
withFooter?: boolean;
fluidHeader?: boolean;
withBosonStyles?: boolean;
withBanner?: boolean;
};
}

export default [
{
Expand Down
22 changes: 4 additions & 18 deletions src/router/routes.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React, { lazy } from "react";
import { RouteProps } from "react-router";
import { lazy } from "react";

import { CONFIG } from "../lib/config";
import { ViewMode } from "../lib/viewMode";
import ViewModePage from "../pages/viewmode/ViewModePage";
import dappRoutes from "./dappRoutes";
import drCenterRoutes from "./drCenterRoutes";
import { IRoutes } from "./types";
const NotFoundPage = lazy(() => import("../pages/not-found/NotFound"));

export const baseAppProps = {
Expand All @@ -28,21 +28,7 @@ export const UserRoles = {
Seller: "Seller",
DisputeResolver: "DisputeResolver"
} as const;
export interface IRoutes extends RouteProps {
component:
| React.ComponentType<any> // eslint-disable-line
| React.LazyExoticComponent<React.ComponentType<any>>; // eslint-disable-line
role: Array<string | null>;
componentProps?: {
[key: string]: string;
};
app?: {
withLayout?: boolean;
withFullLayout?: boolean;
withFooter?: boolean;
fluidHeader?: boolean;
};
}

const viewMode = CONFIG.envViewMode.current;

const viewModeRoutes = {
Expand Down Expand Up @@ -74,7 +60,7 @@ const viewModeRoutes = {
},
component: NotFoundPage
}
]
] as IRoutes[]
} as const;

export default viewModeRoutes[viewMode];
17 changes: 17 additions & 0 deletions src/router/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { RouteProps } from "react-router";

export type IRoutes = RouteProps & {
component:
| React.ComponentType<any> // eslint-disable-line
| React.LazyExoticComponent<React.ComponentType<any>>; // eslint-disable-line
role: Array<string | null>;
componentProps?: {
[key: string]: string;
};
app?: {
withLayout?: boolean;
withFullLayout?: boolean;
withFooter?: boolean;
fluidHeader?: boolean;
};
};

0 comments on commit cf9aa40

Please sign in to comment.