Skip to content

Commit

Permalink
Merge pull request #165 from datagrove/fixViewUserPurchases
Browse files Browse the repository at this point in the history
Fix view user purchases
  • Loading branch information
r-southworth authored Oct 22, 2024
2 parents 7c36f1d + 6c07d66 commit 80ffa4b
Show file tree
Hide file tree
Showing 45 changed files with 4,616 additions and 3,599 deletions.
7,881 changes: 4,419 additions & 3,462 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"prettier": "^3.0.1",
"prettier-plugin-astro": "^0.11.0",
"prettier-plugin-tailwindcss": "^0.5.3",
"supabase": "^1.110.1",
"supabase": "^1.207.9",
"vite-plugin-pwa": "^0.16.5",
"workbox-cli": "^7.0.0",
"workbox-routing": "^7.0.0",
Expand Down
4 changes: 2 additions & 2 deletions src/components/members/CreatorProfileView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ export const CreatorProfileView: Component = () => {
/>
</svg>
<p class="pl-1 text-lg font-light">
{t("pageTitles.createPost")}
{t("buttons.createPost")}
</p>
</button>
</div>
Expand Down Expand Up @@ -544,7 +544,7 @@ export const CreatorProfileView: Component = () => {
/>
</svg>
<p class="pl-1 text-lg font-light ">
{t("pageTitles.createPost")}
{t("buttons.createPost")}
</p>
</button>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/members/CreatorRegistrationRouting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const CreatorRegistrationRouting = () => {
`/${lang}/creator/createaccount`
);
const [createText, setCreateText] = createSignal<string>(
t("pageTitles.createCreatorAccount")
t("h1ElementText.createCreatorAccount")
);

const createCreatorProfileLink = document.getElementById(
Expand Down
1 change: 1 addition & 0 deletions src/components/members/UserProfileView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ export const UserProfileView: Component = () => {
{/* <ViewCard posts={purchasedItems()} /> */}
<ViewUserPurchases
session={session()}
lang={lang}
/>
</div>
{/* </Show>
Expand Down
5 changes: 4 additions & 1 deletion src/components/members/UserProfileViewMobile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,10 @@ export const UserProfileViewMobile: Component<Props> = (props: Props) => {

<Show when={tabSelected() === "purchases"}>
<div>
<ViewUserPurchases session={props.session} />
<ViewUserPurchases
session={props.session}
lang={lang}
/>
</div>
</Show>

Expand Down
8 changes: 3 additions & 5 deletions src/components/members/UserRouting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ export const UserRouting = () => {
const [isUser, setIsUser] = createSignal<boolean>(false);
const [isUserUser, setIsUserUser] = createSignal<boolean>(false);
const [createText, setCreateText] = createSignal<string>(
t("pageTitles.createUserAccount")
);
const [routing, setRouting] = createSignal<string>(
`/${lang}/user/profile`
t("buttons.createUserAccount")
);
const [routing, setRouting] = createSignal<string>(`/${lang}/user/profile`);

const CreateEditUserProfilelink = document.getElementById(
"createEditUserProfileLink"
Expand All @@ -39,7 +37,7 @@ export const UserRouting = () => {
if (data![0] === undefined) {
// console.log("user is not a user");
} else {
setCreateText(t("pageTitles.viewUserAccount"));
setCreateText(t("buttons.viewUserProfile"));
setRouting(`/${lang}/user/profile`);
setIsUserUser(true);
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/posts/FullPostView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@ export const ViewFullPost: Component<Props> = (props) => {
};

const fetchOwnedPost = async function (id: number) {
const { data, error } = supabase.from("orders").select("*");
const { data, error } = await supabase.from("orders").select("*");

if (error) {
console.error(error);
} else {
console.log(data, "0000000000000000000");
console.log(data);
}
};

Expand Down
1 change: 0 additions & 1 deletion src/components/posts/ReviewPurchasedResource.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,6 @@ export const ReviewPurchasedResource: Component<Props> = (props) => {
buttonClass="btn-primary"
buttonContent={"Submit Review"}
buttonId="submitReview"
classList="max-w-[200px]"
children={
<div class="">
<div class="flex">
Expand Down
134 changes: 47 additions & 87 deletions src/components/posts/ViewUserPurchases.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Component } from "solid-js";
import type { User } from "@lib/types";
import type { FilterPostsParams, Post, User } from "@lib/types";
import stripe from "@lib/stripe";
import { createSignal, createEffect, Show, onMount } from "solid-js";
import supabase from "../../lib/supabaseClient.tsx";
Expand All @@ -11,14 +11,9 @@ import { ViewPurchaseCard } from "@components/services/ViewPurchaseCard.tsx";
import { ReviewPurchasedResource } from "@components/posts/ReviewPurchasedResource.tsx";
import type { PurchasedPost } from "@lib/types";

const lang = getLangFromUrl(new URL(window.location.href));
const t = useTranslations(lang);

const values = ui[lang] as uiObject;
const productCategories = values.subjectCategoryInfo.subjects;

interface Props {
session: AuthSession | null;
lang: "en" | "es" | "fr";
}

export const ViewUserPurchases: Component<Props> = (props) => {
Expand All @@ -27,12 +22,31 @@ export const ViewUserPurchases: Component<Props> = (props) => {
Array<PurchasedPost>
>([]);
const [loading, setLoading] = createSignal<boolean>(true);
const lang = props.lang;

const t = useTranslations(lang);

const values = ui[lang] as uiObject;
const productCategories = values.subjectCategoryInfo.subjects;

onMount(async () => {
setSession(props.session);
await getPurchasedItems();
});

async function fetchPosts({ post_id }: FilterPostsParams) {
const response = await fetch("/api/fetchFilterPosts", {
method: "POST",
body: JSON.stringify({
lang: lang,
post_id: post_id,
}),
});
const data = await response.json();

return data;
}

const getPurchasedItems = async () => {
setLoading(true);
console.log("Session Info: ");
Expand Down Expand Up @@ -62,92 +76,38 @@ export const ViewUserPurchases: Component<Props> = (props) => {
);
}

const itemsOrdered = orderDetails?.map((item) => {
const order = orders.find(
(order) => order.order_number === item.order_number
);
if (order) {
return {
...item,
purchaseDate: new Date(order.order_date).toISOString(),
};
} else {
return {
...item,
purchaseDate: new Date("2000-01-01").toISOString(),
};
const itemsOrdered = orderDetails?.map(
(item: { product_id: number; order_number: string }) => {
const order = orders.find(
(order) => order.order_number === item.order_number
);
if (order) {
return {
...item,
purchaseDate: new Date(order.order_date).toISOString(),
};
} else {
return {
...item,
purchaseDate: new Date("2000-01-01").toISOString(),
};
}
}
});
);

const products = orderDetails?.map((item) => item.product_id);
if (products !== undefined) {
//Refactor: Consider making an API call for all the calls to seller_post
const { data: productsInfo, error: productsInfoError } =
await supabase
.from("seller_post")
.select("*")
.order("id", { ascending: false })
.in("id", products);
if (productsInfoError) {
console.log(
"Products Info Error: " +
productsInfoError.code +
" " +
productsInfoError.message
);
return;
const response = await fetchPosts({
post_id: products,
lang: lang,
});

if (response.body.length < 1) {
alert(t("messages.noPost"));
location.href = `/${lang}/resources`;
} else {
console.log(productsInfo);
const newItems = await Promise.all(
productsInfo?.map(async (item) => {
item.subject = [];
productCategories.forEach((productCategories) => {
item.product_subject.map(
(productSubject: string) => {
if (
productSubject === productCategories.id
) {
item.subject.push(
productCategories.name
);
console.log(productCategories.name);
}
}
);
});
delete item.product_subject;

const { data: gradeData, error: gradeError } =
await supabase.from("grade_level").select("*");

if (gradeError) {
console.log(
"supabase error: " + gradeError.message
);
} else {
item.grade = [];
gradeData.forEach((databaseGrade) => {
item.post_grade.map((itemGrade: string) => {
if (
itemGrade ===
databaseGrade.id.toString()
) {
item.grade.push(databaseGrade.grade);
}
});
});
}

if (item.stripe_price_id !== null) {
const priceData = await stripe.prices.retrieve(
item.stripe_price_id
);
item.price = priceData.unit_amount! / 100;
}
console.log(item);
return item;
})
);
const newItems: Post[] = response.body;

itemsOrdered?.sort(function (a, b) {
return b.purchaseDate.localeCompare(a.purchaseDate);
Expand Down
2 changes: 1 addition & 1 deletion src/components/services/ResourcesMain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ export const ResourcesView: Component = () => {
<Show when={screenSize() !== "sm"}>
<div class="mb-2 flex w-full items-center justify-center rounded-lg bg-btn1 opacity-80 dark:bg-btn1-DM md:h-24">
<h1 class="text-center text-lg text-ptext1-DM dark:text-ptext1 md:text-3xl">
{t("pageTitles.services")}
{t("h1ElementText.services")}
</h1>
</div>
</Show>
Expand Down
16 changes: 12 additions & 4 deletions src/components/services/ViewPurchaseCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,16 @@ export const ViewPurchaseCard: Component<Props> = (props) => {
imgURL={post.image_url}
postTitle={post.title}
postCreator={post.seller_name}
purchaseDate={post.purchaseDate}
createdDate={post.created_at}
purchaseDate={
post.purchaseDate
? post.purchaseDate
: "N/A"
}
createdDate={
post.created_date
? post.created_date
: "N/A"
}
/>
</div>
</div>
Expand Down Expand Up @@ -195,7 +203,7 @@ export const ViewPurchaseCard: Component<Props> = (props) => {
{t("menus.purchased")} &nbsp{" "}
</p>
<p class="text-xs font-light">
{post.purchaseDate.slice(0, 10)}
{post.purchaseDate?.slice(0, 10)}
</p>
</div>

Expand All @@ -212,7 +220,7 @@ export const ViewPurchaseCard: Component<Props> = (props) => {
{t("menus.updated")} &nbsp
</p>
<p class="text-xs font-light">
{post.created_at.slice(0, 10)}
{post.created_date}
</p>
</div>
</div>
Expand Down
5 changes: 4 additions & 1 deletion src/i18n/UI/English.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const English = {
createPost: "List Resource in LearnGrove",
},

pageMetaTitles: {
pageTitles: {
services: "Resource Catalog of LearnGrove",
signUp: "Sign Up into your LearnGrove Account",
login: "Login into your LearnGrove Account",
Expand Down Expand Up @@ -155,6 +155,9 @@ export const English = {
reviewResource: "Review",
createFavoriteList: "Create New Favorite List",
createList: "Create List",
createUserAccount: "Create User Profile",
viewUserProfile: "My User Profile",
viewCreatorAccount: "My Creator Profile",
},

messages: {
Expand Down
5 changes: 4 additions & 1 deletion src/i18n/UI/French.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const French = {
createPost: "Répertorier les ressources dans LearnGrove",
},

pageMetaTitles: {
pageTitles: {
services: "Catalogue de ressources de LearnGrove",
signUp: "Inscrivez-vous à votre compte LearnGrove",
login: "Connectez-vous à votre compte LearnGrove",
Expand Down Expand Up @@ -150,6 +150,9 @@ export const French = {
reviewResource: "Critique",
createFavoriteList: "Ajouter une nouvelle liste de favoris",
createList: "Ajouter une liste",
createUserAccount: "Créer un profil utilisateur",
viewUserProfile: "Mon profil utilisateur",
viewCreatorAccount: "Mon profil de créateur",
},

messages: {
Expand Down
5 changes: 4 additions & 1 deletion src/i18n/UI/Spanish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const Spanish = {
createPost: "Listar un Recurso en LearnGrove",
},

pageMetaTitles: {
pageTitles: {
services: "Catalogo de Recursos de LearnGrove",
signUp: "Registrarse y abrir una cuenta en LearnGrove ",
login: "Iniciar sesión en la cuenta de LearnGrove",
Expand Down Expand Up @@ -153,6 +153,9 @@ export const Spanish = {
reviewResource: "Reseña",
createFavoriteList: "Crear Nueva Lista de Favoritos",
createList: "Crear Lista",
createUserAccount: "Crear perfil de usuario",
viewUserProfile: "Mi perfil de usuario",
viewCreatorAccount: "Mi perfil de creador",
},

messages: {
Expand Down
5 changes: 4 additions & 1 deletion src/i18n/uiType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export interface uiObject {



pageMetaTitles: {
pageTitles: {
services: string,
signUp: string,
login: string,
Expand Down Expand Up @@ -158,6 +158,9 @@ export interface uiObject {
reviewResource: string,
createFavoriteList: string,
createList: string,
createUserAccount: string,
viewUserProfile: string,
viewCreatorAccount: string,
};

messages: {
Expand Down
Loading

0 comments on commit 80ffa4b

Please sign in to comment.