From 3131b3fe336ceb1ce799aea219468215d10aedcd Mon Sep 17 00:00:00 2001 From: r-southworth Date: Tue, 1 Oct 2024 16:17:52 -0400 Subject: [PATCH 1/5] switch to APIs for get list of favorite lists, and the items in those lists --- src/components/posts/ViewUserFavorites.tsx | 53 +++--- src/i18n/UI/English.ts | 3 +- src/i18n/UI/French.ts | 3 +- src/i18n/UI/Spanish.ts | 3 +- src/i18n/uiType.ts | 1 + src/pages/api/getFavoritesOnList.ts | 147 +++++++++++++++ src/pages/api/getUserFavorites.ts | 198 +++++++++++++++++++++ 7 files changed, 374 insertions(+), 34 deletions(-) create mode 100644 src/pages/api/getFavoritesOnList.ts create mode 100644 src/pages/api/getUserFavorites.ts diff --git a/src/components/posts/ViewUserFavorites.tsx b/src/components/posts/ViewUserFavorites.tsx index 7ed37d16..763983db 100644 --- a/src/components/posts/ViewUserFavorites.tsx +++ b/src/components/posts/ViewUserFavorites.tsx @@ -25,7 +25,7 @@ const { data: User, error: UserError } = await supabase.auth.getSession(); export const ViewUserFavorites: Component = () => { const [session, setSession] = createSignal(null); - const [favoritedItems, setFavoritedItems] = createSignal>([]); + const [favoritedItems, setFavoritedItems] = createSignal>([]); const [loading, setLoading] = createSignal(true); const screenSize = useStore(windowSize); @@ -58,38 +58,29 @@ export const ViewUserFavorites: Component = () => { const getFavorites = async () => { setLoading(true); - const { data: favorites, error } = await supabase - .from("favorites") - .select("*") - .eq("customer_id", session()?.user.id); - if (error) { - console.log("Favorite Error: " + error.code + " " + error.message); - return; - } - - const favoritesListIds = favorites?.map( - (favorite) => favorite.list_number - ); + const response = await fetch("/api/getUserFavorites", { + method: "POST", + body: JSON.stringify({ + access_token: session()?.access_token, + refresh_token: session()?.refresh_token, + lang: lang, + customer_id: session()?.user.id, + }), + }); - const { data: favoritesProducts, error: favoritesProductsError } = - await supabase - .from("favorites_products") - .select("product_id, list_number") - .in("list_number", favoritesListIds); - if (favoritesProductsError) { - console.log( - "Favorite Details Error: " + - favoritesProductsError.code + - " " + - favoritesProductsError.message - ); + const data = await response.json(); + if (data) { + if (data.type === "single") { + console.log(data); + setFavoritedItems(data.posts.body); + setLoading(false); + } + if (data.type === "multiple") { + console.log(data); + } } - - const products = favoritesProducts?.map((item) => item.product_id); - if (products !== undefined) { - const res = await fetchPosts({ post_id: products, lang: lang }); - setFavoritedItems(res.body); - setLoading(false); + if (response.status !== 200) { + alert(data.message); } }; diff --git a/src/i18n/UI/English.ts b/src/i18n/UI/English.ts index fa6cd070..18dd9a47 100644 --- a/src/i18n/UI/English.ts +++ b/src/i18n/UI/English.ts @@ -398,7 +398,8 @@ export const English = { "Error creating user, please try again or contact us for assistance.", emailNotConfirmed: "Email not registered. If you previously registered this email address please use the forgot password option below, otherwise please use the sign up option below.", - }, + noFavoriteLists: "No Favorite Lists found", + }, socialModal: { shareService: "Share this resource", diff --git a/src/i18n/UI/French.ts b/src/i18n/UI/French.ts index bcbaff67..a6c5d496 100644 --- a/src/i18n/UI/French.ts +++ b/src/i18n/UI/French.ts @@ -401,7 +401,8 @@ export const French = { "Erreur lors de la création de l'utilisateur, veuillez réessayer ou contactez-nous pour obtenir de l'aide.", emailNotConfirmed: "Correo electrónico no registrado. Si registró previamente esta dirección de correo electrónico, utilice la opción de olvidé mi contraseña que aparece a continuación; de lo contrario, utilice la opción de registro que aparece a continuación.", - }, + noFavoriteLists: "Aucune liste de favoris trouvée", + }, socialModal: { shareService: "Partager ce ressource", diff --git a/src/i18n/UI/Spanish.ts b/src/i18n/UI/Spanish.ts index e869ed36..e12a7f1a 100644 --- a/src/i18n/UI/Spanish.ts +++ b/src/i18n/UI/Spanish.ts @@ -401,7 +401,8 @@ export const Spanish = { "Error al crear usuario, inténtelo nuevamente o contáctenos para obtener ayuda.", emailNotConfirmed: "Correo electrónico no registrado. Si registró previamente esta dirección de correo electrónico, utilice la opción de olvidé mi contraseña que aparece a continuación; de lo contrario, utilice la opción de registro que aparece a continuación.", - }, + noFavoriteLists: "No se encontraron lista de favoritos", + }, socialModal: { shareService: "Comparte este recurso", diff --git a/src/i18n/uiType.ts b/src/i18n/uiType.ts index 91dddfac..84934f59 100644 --- a/src/i18n/uiType.ts +++ b/src/i18n/uiType.ts @@ -373,6 +373,7 @@ export interface uiObject { userEditProfileError: string; createUserError: string; emailNotConfirmed: string; + noFavoriteLists: string; }; socialModal: { diff --git a/src/pages/api/getFavoritesOnList.ts b/src/pages/api/getFavoritesOnList.ts new file mode 100644 index 00000000..8aa9ae1b --- /dev/null +++ b/src/pages/api/getFavoritesOnList.ts @@ -0,0 +1,147 @@ +import supabase from "../../lib/supabaseClientServer"; +import type { APIRoute } from "astro"; +import type { APIContext } from "astro"; +import { useTranslations } from "@i18n/utils"; + +export const POST: APIRoute = async ({ request, redirect }) => { + const requestData = await request.json(); + const url = new URL(request.url); + + console.log("GetFavoritesOnList Request", requestData); + + //Set internationalization values + const lang = requestData.lang; + //@ts-ignore + const t = useTranslations(lang); + + const list_number = requestData.list_number; + // const list_name = formData.get("list_name"); + const access_token = requestData.access_token; + const refresh_token = requestData.refresh_token; + const limit = requestData.limit; + // Future work: could add default list here if we want to allow people to change it + + // Validate the formData - you'll probably want to do more than this + if (!list_number) { + return new Response( + JSON.stringify({ + message: t("apiErrors.missingFields"), + }), + { status: 400 } + ); + } + + const { data: sessionData, error: sessionError } = + await supabase.auth.setSession({ + refresh_token: refresh_token!.toString(), + access_token: access_token!.toString(), + }); + if (sessionError) { + return new Response( + JSON.stringify({ + message: t("apiErrors.noSession"), + }), + { status: 500 } + ); + } + + // console.log(sessionData) + + if (!sessionData?.session) { + return new Response( + JSON.stringify({ + message: t("apiErrors.noSession"), + }), + { status: 500 } + ); + } + + const user = sessionData?.session.user; + + if (!user) { + return new Response( + JSON.stringify({ + message: t("apiErrors.noUser"), + }), + { status: 500 } + ); + } + + let query = supabase + .from("favorites_products") + .select("product_id") + .eq("list_number", list_number); + + if (limit) { + query = query.limit(limit); + } + + const { count, error: countError } = await supabase + .from("favorites_products") + .select("product_id", { count: "exact" }) + .eq("list_number", list_number); + + console.log("GetFavoritesOnList Count", count); + + const { data, error } = await query; + + console.log("GetFavoritesOnList Query Response", data); + + //data:[{ + // list_number: uuid + // product_id: int8 + //}] + + if (error) { + console.log(error); + return new Response( + JSON.stringify({ + //TODO Internationalize + message: "Error fetching favorites", + }), + { status: 500 } + ); + } else if (!data || data.length === 0) { + return new Response( + JSON.stringify({ + //TODO Internationalize + message: "Error No favorite items found", + }), + { status: 500 } + ); + } + + const productsInfo = data.map((item) => item.product_id); + if (productsInfo !== undefined) { + const response = await fetch(`${url.origin}/api/fetchFilterPosts`, { + method: "POST", + body: JSON.stringify({ + post_id: productsInfo, + lang: lang, + }), + }); + + const data = await response.json(); + + if (data) { + return new Response( + JSON.stringify({ + message: t("apiErrors.success"), + posts: data, + count: count, + }), + { status: 200 } + ); + } + } + // Return a list of lists with information + // Need the image from the first item on each list + + return new Response( + JSON.stringify({ + // TODO Internationalize + message: "Error Getting User Favorites", + }), + { status: 500 } + ); +}; diff --git a/src/pages/api/getUserFavorites.ts b/src/pages/api/getUserFavorites.ts new file mode 100644 index 00000000..8571cac7 --- /dev/null +++ b/src/pages/api/getUserFavorites.ts @@ -0,0 +1,198 @@ +import supabase from "../../lib/supabaseClientServer"; +import type { APIRoute } from "astro"; +import type { APIContext } from "astro"; +import { useTranslations } from "@i18n/utils"; + +export const POST: APIRoute = async ({ request, redirect }) => { + const requestBody = await request.json(); + const url = new URL(request.url); + + console.log("GetUserFavorites Request", requestBody); + + //Set internationalization values + const lang = requestBody.lang; + //@ts-ignore + const t = useTranslations(lang); + + const customerId = requestBody.customer_id; + // const list_number = formData.get("list_number"); + // const list_name = formData.get("list_name"); + const access_token = requestBody.access_token; + const refresh_token = requestBody.refresh_token; + // Future work: could add default list here if we want to allow people to change it + + // Validate the formData - you'll probably want to do more than this + if (!customerId) { + return new Response( + JSON.stringify({ + message: t("apiErrors.missingFields"), + }), + { status: 400 } + ); + } + + async function getItems(list_number: string, limit?: number) { + let response: ReadableStream; + if(limit){ + response = await fetch(`${url.origin}/api/getFavoritesOnList`, { + method: "POST", + body: JSON.stringify({ + list_number: list_number, + access_token: access_token, + refresh_token: refresh_token, + lang: lang, + limit: limit, + }), + }); + + } else { + response = await fetch(`${url.origin}/api/getFavoritesOnList`, { + method: "POST", + body: JSON.stringify({ + list_number: list_number, + access_token: access_token, + refresh_token: refresh_token, + lang: lang, + }), + }); + + } + + + const data = await response.json(); + return data; + } + + const { data: sessionData, error: sessionError } = + await supabase.auth.setSession({ + refresh_token: refresh_token!.toString(), + access_token: access_token!.toString(), + }); + if (sessionError) { + return new Response( + JSON.stringify({ + message: t("apiErrors.noSession"), + }), + { status: 500 } + ); + } + + // console.log(sessionData) + + if (!sessionData?.session) { + return new Response( + JSON.stringify({ + message: t("apiErrors.noSession"), + }), + { status: 500 } + ); + } + + const user = sessionData?.session.user; + + if (!user) { + return new Response( + JSON.stringify({ + message: t("apiErrors.noUser"), + }), + { status: 500 } + ); + } + + // let favoritesLists: [] = []; + // if (!list_number) { + // favoritesLists = JSON.parse(list_number as Number); + // } + // console.log(favoritesLists); + + const { error, data } = await supabase + .from("favorites") + .select("*") + .eq("customer_id", customerId); + + //data:[{ + // list_name: text + // list_number: uuid + // customer_id: uuid + // created_date: timestamp + // default_list: boolean + //}] + + if (error) { + console.log(error); + return new Response( + JSON.stringify({ + //TODO Fix error message + message: t("apiErrors.postError"), + }), + { status: 500 } + ); + } else if (!data) { + return new Response( + JSON.stringify({ + message: t("apiErrors.noFavoriteLists"), + }), + { status: 500 } + ); + } + + if (data.length === 0) { + return new Response( + JSON.stringify({ + message: t("apiErrors.noFavoriteLists"), + }), + { status: 500 } + ); + } else if (data.length === 1) { + // Make favorites Items call here + const response = await getItems(data[0].list_number); + + if (response) { + return new Response( + JSON.stringify({ + message: t("apiErrors.success"), + type: "single", + posts: response.posts, + }), + { status: 200 }, + ); + } else { + return new Response( + JSON.stringify({ + // TODO Internationalize + message: "Error Getting User Favorites", + }), + { status: 500 } + ); + } + + } else { + // Return a list of lists with information + let listData = data; + listData.map(async (list) => { + const response = await getItems(list.list_number); + list.count = response.count + list.image = response.posts[0].image_urls[0] + return list + }) + console.log(listData); + // Need the image from the first item on each list + return new Response( + JSON.stringify({ + message: t("apiErrors.success"), + id: data, + type: "list", + }), + { status: 200 } + ); + } + + return new Response( + JSON.stringify({ + // TODO Internationalize + message: "Error Getting User Favorites", + }), + { status: 500 } + ); +}; + From 7b3f22414dfd0a705c19424559c1d60fdef8461e Mon Sep 17 00:00:00 2001 From: r-southworth Date: Thu, 3 Oct 2024 18:09:17 -0400 Subject: [PATCH 2/5] multiple favorites list --- src/components/common/notices/modal.tsx | 68 ++- src/components/members/UserProfileView.tsx | 8 +- .../members/user/createFavoriteList.tsx | 79 +++ src/components/posts/AddFavorite.tsx | 459 ++++++++++++------ src/components/posts/ViewUserFavorites.tsx | 172 ++++++- src/components/services/FiltersMobile.tsx | 13 +- src/i18n/UI/English.ts | 4 + src/i18n/UI/French.ts | 4 + src/i18n/UI/Spanish.ts | 4 + src/i18n/uiType.ts | 82 +--- src/lib/types.ts | 11 +- src/pages/api/fetchFilterPosts.ts | 7 +- src/pages/api/getFavoritesOnList.ts | 16 +- src/pages/api/getUserFavoriteIds.ts | 82 ++++ src/pages/api/getUserFavorites.ts | 101 ++-- 15 files changed, 816 insertions(+), 294 deletions(-) create mode 100644 src/components/members/user/createFavoriteList.tsx create mode 100644 src/pages/api/getUserFavoriteIds.ts diff --git a/src/components/common/notices/modal.tsx b/src/components/common/notices/modal.tsx index 8d86492f..94f3dda6 100644 --- a/src/components/common/notices/modal.tsx +++ b/src/components/common/notices/modal.tsx @@ -2,26 +2,45 @@ import type { Component, JSX } from "solid-js"; import { createSignal, createEffect, onCleanup, Show } from "solid-js"; import { getHeading } from "./utils"; import type { HeadingProps } from "./utils"; +import { createStore } from "solid-js/store"; type ModalProps = { children: JSX.Element; buttonClass: string; buttonId: string; buttonContent: JSX.Element; + buttonAriaLabel?: string; heading: HeadingProps["heading"]; headingLevel?: HeadingProps["headingLevel"]; - classList?: string; + //classList?: string; }; +export const [isOpen, setIsOpen] = createSignal>({}); + +export function openModal(modalId: string, e?: Event) { + e?.preventDefault(); + e?.stopPropagation(); + setIsOpen((prev) => ({ ...prev, [modalId]: true })); +} + +export function closeModal(modalId: string, e?: Event) { + e?.preventDefault(); + e?.stopPropagation(); + setIsOpen((prev) => ({ ...prev, [modalId]: false })); +} + +export function isModalOpen(modalId: string) { + return isOpen()[modalId]; +} + const Modal: Component = (props) => { - const [isOpen, setIsOpen] = createSignal(false); const [modal, setModal] = createSignal(null); const focusableElements = 'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'; createEffect(() => { - if (isOpen()) { + if (isModalOpen(props.buttonId)) { console.log("modal open"); const originalFocusedElement = document.activeElement as HTMLElement; @@ -37,7 +56,7 @@ const Modal: Component = (props) => { const isTabPressed = (key || code) === "Tab"; const isEscapePressed = (key || code) === "Escape"; if (!isTabPressed && !isEscapePressed) return; - if (isEscapePressed) return setIsOpen(false); + if (isEscapePressed) return closeModal(props.buttonId, e); if (shiftKey) { // if shift key pressed for shift + tab combination if (document.activeElement === firstFocusableElement) { @@ -60,43 +79,46 @@ const Modal: Component = (props) => { } }); - function openModal (e: Event) { - e.preventDefault(); - e.stopPropagation(); - setIsOpen(true); - } + // function openModal(e: Event) { + // e.preventDefault(); + // e.stopPropagation(); + // setIsOpen(true); + // } + + // function closeModal(e: Event) { + // e.preventDefault(); + // e.stopPropagation(); + // setIsOpen(false); + // } - function closeModal (e: Event) { - e.preventDefault(); - e.stopPropagation(); - setIsOpen(false); - } - return ( <> - + From 44aca0e3ed0599120ffbc4e059aea15f256cbee2 Mon Sep 17 00:00:00 2001 From: r-southworth Date: Mon, 7 Oct 2024 17:46:42 -0400 Subject: [PATCH 5/5] Internationalize --- src/components/posts/AddFavorite.tsx | 25 +++++++++++----------- src/components/posts/ViewUserFavorites.tsx | 3 +-- src/i18n/UI/English.ts | 7 ++++++ src/i18n/UI/French.ts | 7 ++++++ src/i18n/UI/Spanish.ts | 7 ++++++ src/i18n/uiType.ts | 7 ++++++ src/pages/api/getFavoritesOnList.ts | 9 +++----- src/pages/api/getUserFavoriteIds.ts | 9 +++----- src/pages/api/getUserFavorites.ts | 13 ++++------- 9 files changed, 51 insertions(+), 36 deletions(-) diff --git a/src/components/posts/AddFavorite.tsx b/src/components/posts/AddFavorite.tsx index 07e2e8ec..8e037ce5 100644 --- a/src/components/posts/AddFavorite.tsx +++ b/src/components/posts/AddFavorite.tsx @@ -275,8 +275,9 @@ export const FavoriteButton: Component = (props) => { heading={"Save To"} buttonId={`addFavoriteBtn ${props.id}`} buttonClass="absolute right-0 top-0 z-30" - // TODO Internationalize - buttonAriaLabel={`Add to Favorites ${props.id}`} + buttonAriaLabel={ + t("ariaLabels.addToFavorites") + " " + props.id + } buttonContent={ = (props) => { onclick={(e) => notSignedInAdd(e)} class="absolute right-0 top-0" id="addFavoriteBtn" - aria-label={`Add to Favorites ${props.id}`} + aria-label={ + t("ariaLabels.addToFavorites") + " " + props.id + } > = (props) => { lang={lang} user_id={session()?.user.id || ""} onListCreated={getFavoriteLists} - //TODO Internationalize - buttonContent={"+ Create New List"} + buttonContent={ + "+ " + t("buttons.createList") + } /> @@ -419,8 +423,9 @@ export const FavoriteButton: Component = (props) => { heading={"Save To"} buttonId={`addFavoriteBtn ${props.id}`} buttonClass="absolute right-0 top-0" - // TODO Internationalize - buttonAriaLabel={`Add to Favorites ${props.id}`} + buttonAriaLabel={ + t("ariaLabels.addToFavorites") + " " + props.id + } buttonContent={ = (props) => { } headingLevel={6} > - {/* */}
diff --git a/src/components/posts/ViewUserFavorites.tsx b/src/components/posts/ViewUserFavorites.tsx index 04102d78..fc39f002 100644 --- a/src/components/posts/ViewUserFavorites.tsx +++ b/src/components/posts/ViewUserFavorites.tsx @@ -118,8 +118,7 @@ export const ViewUserFavorites: Component = () => { setListName(list_name); setListNumber(list_id); } else { - //TODO Internationalize - alert("No posts to display"); + alert(t("messages.noPosts")); setFavoritedItems([]); setLoading(false); } diff --git a/src/i18n/UI/English.ts b/src/i18n/UI/English.ts index abf94d0b..a847ee71 100644 --- a/src/i18n/UI/English.ts +++ b/src/i18n/UI/English.ts @@ -403,6 +403,12 @@ export const English = { emailNotConfirmed: "Email not registered. If you previously registered this email address please use the forgot password option below, otherwise please use the sign up option below.", noFavoriteLists: "No Favorite Lists found", + noFavoriteItems: "Error: No favorite items found", + errorFavoriteFetch: "Error fetching favorites", + generalErrorFavorite: "Error Getting User Favorites", + singleListFavoriteError: "Error getting single list favorites", + favoriteListError: "Error fetching favorite list", + multipleListFavoriteError: "Error handling multiple lists", }, socialModal: { @@ -436,6 +442,7 @@ export const English = { checkboxGrade: "Checkbox for selecting grade level", checkbox: "Checkbox", readMoreAbout: "Read more about ", + addToFavorites: "Add to Favorites", }, headerData: { diff --git a/src/i18n/UI/French.ts b/src/i18n/UI/French.ts index 396c8a76..d0af2ea0 100644 --- a/src/i18n/UI/French.ts +++ b/src/i18n/UI/French.ts @@ -442,6 +442,13 @@ export const French = { checkboxGrade: "Case à cocher pour sélectionner le niveau scolaire", checkbox: "Case à cocher", readMoreAbout: "En savoir plus sur", + addToFavorites: "Ajouter aux favoris", + noFavoriteItems: "Aucun favori", + errorFavoriteFetch: "Erreur lors de la recuperation des favoris", + generalErrorFavorite: "Erreur lors de la recuperation des favoris", + singleListFavoriteError: "Erreur lors de l'obtention d'une seule liste de favoris", + favoriteListError: "Erreur lors de l'obtention de la liste de favoris", + multipleListFavoriteError: "Erreur lors de l'analyse de plusieurs listes de favoris", }, headerData: { diff --git a/src/i18n/UI/Spanish.ts b/src/i18n/UI/Spanish.ts index a5b630d3..867864cb 100644 --- a/src/i18n/UI/Spanish.ts +++ b/src/i18n/UI/Spanish.ts @@ -443,6 +443,13 @@ export const Spanish = { "Casilla de verificación para seleccionar el nivel de grado", checkbox: "Caja", readMoreAbout: "Leer más sobre", + addToFavorites: "Añadir a favoritos", + noFavoriteItems: "No hay elementos favoritos", + errorFavoriteFetch: "Error al obtener favoritos", + generalErrorFavorite: "Error al obtener favoritos", + singleListFavoriteError: "Error al obtener favoritos de lista única", + favoriteListError: "Error al obtener lista de favoritos", + multipleListFavoriteError: "Error al manejar varias listas", }, headerData: { diff --git a/src/i18n/uiType.ts b/src/i18n/uiType.ts index 394e7f0d..3227f686 100644 --- a/src/i18n/uiType.ts +++ b/src/i18n/uiType.ts @@ -391,6 +391,12 @@ export interface uiObject { createUserError: string; emailNotConfirmed: string; noFavoriteLists: string; + noFavoriteItems: string; + errorFavoriteFetch: string; + generalErrorFavorite: string; + singleListFavoriteError: string; + favoriteListError: string; + multipleListFavoriteError: string; }; socialModal: { @@ -423,6 +429,7 @@ export interface uiObject { checkboxGrade: string; checkbox: string; readMoreAbout: string; + addToFavorites: string; }; headerData: { diff --git a/src/pages/api/getFavoritesOnList.ts b/src/pages/api/getFavoritesOnList.ts index 1c9595c1..f4c482c6 100644 --- a/src/pages/api/getFavoritesOnList.ts +++ b/src/pages/api/getFavoritesOnList.ts @@ -91,16 +91,14 @@ export const POST: APIRoute = async ({ request, redirect }) => { console.log(error); return new Response( JSON.stringify({ - //TODO Internationalize - message: "Error fetching favorites", + message: t("apiErrors.errorFavoriteFetch"), }), { status: 500 } ); } else if (!data) { return new Response( JSON.stringify({ - //TODO Internationalize - message: "Error No favorite items found", + message: t("apiErrors.noFavoriteItems"), }), { status: 500 } ); @@ -143,8 +141,7 @@ export const POST: APIRoute = async ({ request, redirect }) => { return new Response( JSON.stringify({ - // TODO Internationalize - message: "Error Getting User Favorites", + message: t("apiErrors.generalErrorFavorite"), }), { status: 500 } ); diff --git a/src/pages/api/getUserFavoriteIds.ts b/src/pages/api/getUserFavoriteIds.ts index 0aeb5cd0..0a7826a1 100644 --- a/src/pages/api/getUserFavoriteIds.ts +++ b/src/pages/api/getUserFavoriteIds.ts @@ -37,8 +37,7 @@ export const POST: APIRoute = async ({ request, redirect }) => { if (error) { return new Response( JSON.stringify({ - //TODO Fix error message - message: t("apiErrors.postError"), + message: t("apiErrors.favoriteListError"), }), { status: 500 } ); @@ -55,8 +54,7 @@ export const POST: APIRoute = async ({ request, redirect }) => { if (favoritesProductsError) { return new Response( JSON.stringify({ - // TODO Internationalize - message: "Error Getting User Favorites from Single List", + message: t("apiErrors.singleListFavoriteError"), }), { status: 500 } ); @@ -74,8 +72,7 @@ export const POST: APIRoute = async ({ request, redirect }) => { return new Response( JSON.stringify({ - // TODO Internationalize - message: "GeneralError Getting User Favorites", + message: t("apiErrors.generalErrorFavorite"), }), { status: 500 } ); diff --git a/src/pages/api/getUserFavorites.ts b/src/pages/api/getUserFavorites.ts index e1522886..15ac579b 100644 --- a/src/pages/api/getUserFavorites.ts +++ b/src/pages/api/getUserFavorites.ts @@ -162,18 +162,15 @@ export const POST: APIRoute = async ({ request, redirect }) => { } else { return new Response( JSON.stringify({ - // TODO Internationalize - message: "Error Getting User Favorites from Single List", + message: t("apiErrors.singleListFavoriteError"), }), { status: 500 } ); } } catch (error) { - console.error("Error handling single list:", error); return new Response( - //TODO Internationalize JSON.stringify({ - message: "Error handling single list", + message: t("apiErrors.singleListFavoriteError"), }), { status: 500 } ); @@ -202,9 +199,8 @@ export const POST: APIRoute = async ({ request, redirect }) => { } catch (error) { console.error("Error handling multiple lists:", error); return new Response( - //TODO Internationalize JSON.stringify({ - message: "Error handling multiple lists", + message: t("apiErrors.multipleListFavoriteError"), }), { status: 500 } ); @@ -213,8 +209,7 @@ export const POST: APIRoute = async ({ request, redirect }) => { return new Response( JSON.stringify({ - // TODO Internationalize - message: "GeneralError Getting User Favorites", + message: t("apiErrors.generalErrorFavorite"), }), { status: 500 } );