chore: teams filter improvements (#14315)
* Changed translations, many languages were wrong * Clear localStorage from the useTypedQuery * Missed one
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -253,7 +253,7 @@
|
||||
"forgot": "Забыли пароль?",
|
||||
"done": "Готово",
|
||||
"all_done": "Готово!",
|
||||
"all": "Все приложения",
|
||||
"all": "Все",
|
||||
"yours": "Ваш аккаунт",
|
||||
"available_apps": "Доступные приложения",
|
||||
"available_apps_lower_case": "Доступные приложения",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user