feat: Relevance option for sorting (#2968)

Co-authored-by: pandeymangg <anshuman.pandey9999@gmail.com>
Co-authored-by: Anshuman Pandey <54475686+pandeymangg@users.noreply.github.com>
This commit is contained in:
Dhruwang Jariwala
2024-09-03 16:13:55 +05:30
committed by GitHub
parent b10d398728
commit 4003d21826
10 changed files with 217 additions and 54 deletions
@@ -8,6 +8,7 @@ import { useRouter } from "next/navigation";
import { useForm } from "react-hook-form";
import { toast } from "react-hot-toast";
import { getFormattedErrorMessage } from "@formbricks/lib/actionClient/helper";
import { FORMBRICKS_PRODUCT_ID_LS, FORMBRICKS_SURVEYS_FILTERS_KEY_LS } from "@formbricks/lib/localStorage";
import { PREVIEW_SURVEY } from "@formbricks/lib/styling/constants";
import {
TProductConfigChannel,
@@ -59,6 +60,14 @@ export const ProductSettings = ({
const productionEnvironment = createProductResponse.data.environments.find(
(environment) => environment.type === "production"
);
if (productionEnvironment) {
if (typeof window !== "undefined") {
localStorage.setItem(FORMBRICKS_PRODUCT_ID_LS, productionEnvironment.productId);
// Rmove filters when creating a new product
localStorage.removeItem(FORMBRICKS_SURVEYS_FILTERS_KEY_LS);
}
}
if (channel !== "link") {
router.push(`/environments/${productionEnvironment?.id}/connect`);
} else {
@@ -30,6 +30,7 @@ import Link from "next/link";
import { usePathname, useRouter } from "next/navigation";
import { useEffect, useMemo, useState } from "react";
import { cn } from "@formbricks/lib/cn";
import { FORMBRICKS_PRODUCT_ID_LS, FORMBRICKS_SURVEYS_FILTERS_KEY_LS } from "@formbricks/lib/localStorage";
import { getAccessFlags } from "@formbricks/lib/membership/utils";
import { capitalizeFirstLetter } from "@formbricks/lib/utils/strings";
import { TEnvironment } from "@formbricks/types/environment";
@@ -114,6 +115,16 @@ export const MainNavigation = ({
}
}, [organization]);
useEffect(() => {
if (typeof window === "undefined") return;
const productId = localStorage.getItem(FORMBRICKS_PRODUCT_ID_LS);
const targetProduct = products.find((product) => product.id === productId);
if (targetProduct && productId && product && product.id !== targetProduct.id) {
router.push(`/products/${targetProduct.id}/`);
}
}, []);
const sortedOrganizations = useMemo(() => {
return [...organizations].sort((a, b) => a.name.localeCompare(b.name));
}, [organizations]);
@@ -140,6 +151,12 @@ export const MainNavigation = ({
}, [products]);
const handleEnvironmentChangeByProduct = (productId: string) => {
if (typeof window !== "undefined") {
localStorage.setItem(FORMBRICKS_PRODUCT_ID_LS, productId);
// Remove filters when switching products
localStorage.removeItem(FORMBRICKS_SURVEYS_FILTERS_KEY_LS);
}
router.push(`/products/${productId}/`);
};
+1
View File
@@ -51,5 +51,6 @@ export const updateResponse = async (
};
export const formbricksLogout = async () => {
localStorage.clear();
return await formbricks.logout();
};
+1
View File
@@ -105,6 +105,7 @@ test.describe("JS Package Test", async () => {
(await page.waitForSelector("text=Responses")).isVisible();
await page.waitForLoadState("networkidle");
await page.waitForTimeout(2000);
const impressionsCount = await page.getByRole("button", { name: "Impressions" }).innerText();
expect(impressionsCount).toEqual("Impressions\n\n1");