Skip to content

Scheduling infrastructure for absolutely everyone.

chore: teams filter improvements (#14315)

Alex van Andel1132d9d0dce6
diff --git a/apps/web/public/static/locales/cs/common.json b/apps/web/public/static/locales/cs/common.json
index b86eca62cd4..086f2d0b6d6 100644
--- a/apps/web/public/static/locales/cs/common.json
+++ b/apps/web/public/static/locales/cs/common.json
@@ -252,7 +252,7 @@
"forgot": "Zapomněli jste?",
"done": "Hotovo",
"all_done": "Hotovo!",
- "all": "Všechny aplikace",
+ "all": "Všechny",
"yours": "Váš účet",
"available_apps": "Dostupné aplikace",
"available_apps_lower_case": "Dostupné aplikace",
diff --git a/apps/web/public/static/locales/de/common.json b/apps/web/public/static/locales/de/common.json
index e05944ebe31..f82f73c12d1 100644
--- a/apps/web/public/static/locales/de/common.json
+++ b/apps/web/public/static/locales/de/common.json
@@ -277,7 +277,7 @@
"forgot": "Vergessen?",
"done": "Erledigt",
"all_done": "Erledigt!",
- "all": "Alle Apps",
+ "all": "Alle",
"yours": "Ihr Konto",
"available_apps": "Verfügbare Apps",
"available_apps_lower_case": "Verfügbare Apps",
diff --git a/apps/web/public/static/locales/es/common.json b/apps/web/public/static/locales/es/common.json
index d3480724cab..4aed24b28c6 100644
--- a/apps/web/public/static/locales/es/common.json
+++ b/apps/web/public/static/locales/es/common.json
@@ -252,7 +252,7 @@
"forgot": "¿Olvidado?",
"done": "Hecho",
"all_done": "¡Todo listo!",
- "all": "Todas las aplicaciones",
+ "all": "Todos",
"yours": "Su cuenta",
"available_apps": "Aplicaciones disponibles",
"available_apps_lower_case": "Aplicaciones disponibles",
diff --git a/apps/web/public/static/locales/it/common.json b/apps/web/public/static/locales/it/common.json
index 63d385e45c2..d15879fecba 100644
--- a/apps/web/public/static/locales/it/common.json
+++ b/apps/web/public/static/locales/it/common.json
@@ -277,7 +277,7 @@
"forgot": "Dimenticato?",
"done": "Fatto",
"all_done": "Operazione completata!",
- "all": "Tutte le app",
+ "all": "Tutte",
"yours": "Il tuo account",
"available_apps": "Applicazioni disponibili",
"available_apps_lower_case": "Applicazioni disponibili",
diff --git a/apps/web/public/static/locales/nl/common.json b/apps/web/public/static/locales/nl/common.json
index 680ac7637c5..f6a243e59f8 100644
--- a/apps/web/public/static/locales/nl/common.json
+++ b/apps/web/public/static/locales/nl/common.json
@@ -252,7 +252,7 @@
"forgot": "Vergeten?",
"done": "Voltooid",
"all_done": "Helemaal klaar!",
- "all": "Alle apps",
+ "all": "Alle",
"yours": "Uw account",
"available_apps": "Beschikbare apps",
"available_apps_lower_case": "Beschikbare apps",
diff --git a/apps/web/public/static/locales/pt-BR/common.json b/apps/web/public/static/locales/pt-BR/common.json
index b784db53167..e64c8ea91ef 100644
--- a/apps/web/public/static/locales/pt-BR/common.json
+++ b/apps/web/public/static/locales/pt-BR/common.json
@@ -279,7 +279,7 @@
"forgot": "Esqueceu?",
"done": "Concluído",
"all_done": "Tudo pronto!",
- "all": "Todos os apps",
+ "all": "Todos",
"yours": "Sua conta",
"available_apps": "Aplicativos disponíveis",
"available_apps_lower_case": "Aplicativos disponíveis",
diff --git a/apps/web/public/static/locales/pt/common.json b/apps/web/public/static/locales/pt/common.json
index 93cfcaa5b34..0ae24e52e14 100644
--- a/apps/web/public/static/locales/pt/common.json
+++ b/apps/web/public/static/locales/pt/common.json
@@ -277,7 +277,7 @@
"forgot": "Esqueceu-se?",
"done": "Concluído",
"all_done": "Tudo pronto!",
- "all": "Todos as aplicações",
+ "all": "Todos",
"yours": "A sua conta",
"available_apps": "Aplicações disponíveis",
"available_apps_lower_case": "Aplicações disponíveis",
diff --git a/apps/web/public/static/locales/ro/common.json b/apps/web/public/static/locales/ro/common.json
index fe9f6c43876..8978cd66236 100644
--- a/apps/web/public/static/locales/ro/common.json
+++ b/apps/web/public/static/locales/ro/common.json
@@ -252,7 +252,7 @@
"forgot": "Ai uitat?",
"done": "Adoptat",
"all_done": "Gata!",
- "all": "Toate aplicațiile",
+ "all": "Toate",
"yours": "Contul dvs.",
"available_apps": "Aplicații disponibile",
"available_apps_lower_case": "Aplicații disponibile",
diff --git a/apps/web/public/static/locales/ru/common.json b/apps/web/public/static/locales/ru/common.json
index 96098be8536..5cdfcffeab9 100644
--- a/apps/web/public/static/locales/ru/common.json
+++ b/apps/web/public/static/locales/ru/common.json
@@ -253,7 +253,7 @@
"forgot": "Забыли пароль?",
"done": "Готово",
"all_done": "Готово!",
- "all": "Все приложения",
+ "all": "Все",
"yours": "Ваш аккаунт",
"available_apps": "Доступные приложения",
"available_apps_lower_case": "Доступные приложения",
diff --git a/apps/web/public/static/locales/sr/common.json b/apps/web/public/static/locales/sr/common.json
index e3f9c877032..0a667ee9a10 100644
--- a/apps/web/public/static/locales/sr/common.json
+++ b/apps/web/public/static/locales/sr/common.json
@@ -252,7 +252,7 @@
"forgot": "Zaboravili ste?",
"done": "Urađeno",
"all_done": "Završeno!",
- "all": "Sve aplikacije",
+ "all": "Sve",
"yours": "Vaš nalog",
"available_apps": "Dostupne aplikacije",
"available_apps_lower_case": "Dostupne aplikacije",
diff --git a/packages/features/filters/components/TeamsFilter.tsx b/packages/features/filters/components/TeamsFilter.tsx
index 4648ac8f5c2..74700545ccc 100644
--- a/packages/features/filters/components/TeamsFilter.tsx
+++ b/packages/features/filters/components/TeamsFilter.tsx
@@ -15,10 +15,9 @@ import { filterQuerySchema } from "../lib/getTeamsFiltersFromQuery";
export type IEventTypesFilters = RouterOutputs["viewer"]["eventTypes"]["listWithTeam"];
export type IEventTypeFilter = IEventTypesFilters[0];
-export const TEAMS_FILTER_KEY = "TEAMS_FILTER_KEY";
function useFilterQuery() {
// passthrough allows additional params to not be removed
- return useTypedQuery(filterQuerySchema.passthrough(), TEAMS_FILTER_KEY);
+ return useTypedQuery(filterQuerySchema.passthrough());
}
export const TeamsFilter = ({
@@ -32,11 +31,14 @@ export const TeamsFilter = ({
}) => {
const { t } = useLocale();
const session = useSession();
+
const { data: query, pushItemToKey, removeItemByKeyAndValue, removeAllQueryParams } = useFilterQuery();
+
const { data: teams } = trpc.viewer.teams.list.useQuery(undefined, {
// Teams don't change that frequently
refetchOnWindowFocus: false,
});
+
const getCheckedOptionsNames = () => {
const checkedOptions: string[] = [];
const teamIds = query.teamIds;
diff --git a/packages/lib/hooks/useTypedQuery.ts b/packages/lib/hooks/useTypedQuery.ts
index 24a6b019568..c17b4afd94f 100644
--- a/packages/lib/hooks/useTypedQuery.ts
+++ b/packages/lib/hooks/useTypedQuery.ts
@@ -4,7 +4,6 @@ import { usePathname, useRouter } from "next/navigation";
import { useCallback, useMemo, useEffect } from "react";
import { z } from "zod";
-import { localStorage } from "../webstorage";
import { useRouterQuery } from "./useRouterQuery";
type OptionalKeys<T> = {
@@ -33,7 +32,7 @@ export const queryStringArray = z
.preprocess((a) => z.string().parse(a).split(","), z.string().array())
.or(z.string().array());
-export function useTypedQuery<T extends z.AnyZodObject>(schema: T, localStorageKey: string | null = null) {
+export function useTypedQuery<T extends z.AnyZodObject>(schema: T) {
type Output = z.infer<typeof schema>;
type FullOutput = Required<Output>;
type OutputKeys = Required<keyof FullOutput>;
@@ -44,7 +43,6 @@ export function useTypedQuery<T extends z.AnyZodObject>(schema: T, localStorageK
const unparsedQuery = useRouterQuery();
const pathname = usePathname();
const parsedQuerySchema = schema.safeParse(unparsedQuery);
- const useLocalStorage = !!localStorageKey;
let parsedQuery: Output = useMemo(() => {
return {} as Output;
}, []);
@@ -74,39 +72,6 @@ export function useTypedQuery<T extends z.AnyZodObject>(schema: T, localStorageK
// eslint-disable-next-line react-hooks/exhaustive-deps
[parsedQuery, router]
);
- //If the value for {localStorageKey} exist in localStorage set it to queryParams
- useEffect(() => {
- if (!useLocalStorage) return;
- const storedValueString = localStorage.getItem(localStorageKey);
- if (!storedValueString || storedValueString == "{}") return;
- const storedValue: Output = JSON.parse(storedValueString);
- if (storedValue) {
- const searchParams = new URLSearchParams();
- for (const [key, value] of Object.entries(storedValue)) {
- searchParams.set(String(key), String(value));
- }
- router.replace(`${pathname}?${searchParams.toString()}`);
- }
- }, []);
-
- function setLocalStorage<J extends OutputKeys>(key: J, value: Output[J]) {
- if (!useLocalStorage) return;
- const storedValue: Output = JSON.parse(localStorage.getItem(localStorageKey) || "{}");
- const newValue = { ...storedValue, [key]: value };
- localStorage.setItem(localStorageKey, JSON.stringify(newValue));
- }
- function removeByKeyFromLocalStorage(key: OutputOptionalKeys) {
- if (!useLocalStorage) return;
- const storedValue: Output = JSON.parse(localStorage.getItem(localStorageKey) || "{}");
- const newValue = storedValue;
- delete newValue[key];
- localStorage.setItem(localStorageKey, JSON.stringify(newValue));
- }
- //Remove {localStorageKey} from the localStorage
- function removeAllValuesFromLocalStorage() {
- if (!useLocalStorage) return;
- localStorage.removeItem(localStorageKey);
- }
// Delete a key from the query
function removeByKey(key: OutputOptionalKeys) {
@@ -122,13 +87,9 @@ export function useTypedQuery<T extends z.AnyZodObject>(schema: T, localStorageK
if (existingValue.includes(value)) return; // prevent adding the same value to the array
// @ts-expect-error this is too much for TS it seems
setQuery(key, [...existingValue, value]);
- // @ts-expect-error this is too much for TS it seems
- setLocalStorage(key, [...existingValue, value]);
} else {
// @ts-expect-error this is too much for TS it seems
setQuery(key, [value]);
- // @ts-expect-error this is too much for TS it seems
- setLocalStorage(key, [value]);
}
}
@@ -139,12 +100,9 @@ export function useTypedQuery<T extends z.AnyZodObject>(schema: T, localStorageK
// @ts-expect-error this is too much for TS it seems
const newValue = existingValue.filter((item) => item !== value);
setQuery(key, newValue);
- setLocalStorage(key, newValue);
} else {
// @ts-expect-error this is too much for TS it seems
removeByKey(key);
- //@ts-expect-error this is too much for TS it seems
- removeByKeyFromLocalStorage(key);
}
}
@@ -152,7 +110,6 @@ export function useTypedQuery<T extends z.AnyZodObject>(schema: T, localStorageK
function removeAllQueryParams() {
if (pathname !== null) {
router.replace(pathname);
- removeAllValuesFromLocalStorage();
}
}