Skip to content

Commit

Permalink
Merge branch 'next-release' into reportResource
Browse files Browse the repository at this point in the history
  • Loading branch information
r-southworth authored Aug 1, 2024
2 parents 4d297ee + d0b61b1 commit 0065ee0
Show file tree
Hide file tree
Showing 18 changed files with 856 additions and 191 deletions.
2 changes: 2 additions & 0 deletions src/assets/heart.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
113 changes: 11 additions & 102 deletions src/components/members/UserProfileView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import stripe from "@lib/stripe";
import { UserProfileViewMobile } from "@components/members/UserProfileViewMobile";
import { useStore } from "@nanostores/solid";
import { windowSize } from "@components/common/WindowSizeStore";
import { ViewUserFavorites } from "@components/posts/ViewUserFavorites";

const lang = getLangFromUrl(new URL(window.location.href));
const t = useTranslations(lang);
Expand Down Expand Up @@ -77,104 +78,6 @@ export const UserProfileView: Component = () => {
// }
// });

const getPurchasedItems = async () => {
console.log("Session Info: ");
console.log(session());
const { data: orders, error } = await supabase
.from("orders")
.select("*")
.eq("customer_id", session()?.user.id);
if (error) {
console.log("Orders Error: " + error.code + " " + error.message);
return;
}
const orderedItemsIds = orders?.map((order) => order.order_number);

const { data: orderDetails, error: orderDetailsError } = await supabase
.from("order_details")
.select("product_id")
.in("order_number", orderedItemsIds);
if (orderDetailsError) {
console.log(
"Order Details Error: " +
orderDetailsError.code +
" " +
orderDetailsError.message
);
}
const products = orderDetails?.map((item) => item.product_id);
console.log(products);
if (products !== undefined) {
const { data: productsInfo, error: productsInfoError } =
await supabase
.from("sellerposts")
.select("*")
.order("id", { ascending: false })
.in("id", products);
if (productsInfoError) {
console.log(
"Products Info Error: " +
productsInfoError.code +
" " +
productsInfoError.message
);
return;
} else {
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.price_id !== null) {
const priceData = await stripe.prices.retrieve(
item.price_id
);
item.price = priceData.unit_amount! / 100;
}
return item;
})
);
setPurchasedItems(newItems);
console.log(purchasedItems());
}
}
};

const fetchUser = async (user_id: string) => {
try {
const { data, error } = await supabase
Expand Down Expand Up @@ -436,8 +339,14 @@ export const UserProfileView: Component = () => {
{t("menus.profile")}
</a>

<a
id="user-profile-tab-favorites-link"
class="user-profile-tab-link mr-4 text-sm font-bold"
onClick={(e) => tabClick(e)}
>
{t("menus.favorites")}
</a>
{/* TODO: Add Back when feature is ready
<a id="user-profile-tab-favorites-link" class="user-profile-tab-link font-bold mr-4 text-sm" onClick={ (e) => tabClick(e) }>{t("menus.favorites")}</a>
<a id="user-profile-tab-following-link" class="user-profile-tab-link font-bold mr-4 text-sm" onClick={ (e) => tabClick(e) }>{t("menus.following")}</a>
*/}
</div>
Expand Down Expand Up @@ -599,9 +508,9 @@ export const UserProfileView: Component = () => {
</Show>

<Show when={tabSelected() === "favorites"}>
<p class="italic">
{t("messages.comingSoon")}
</p>
<div id="favorites">
<ViewUserFavorites />
</div>
</Show>

<Show when={tabSelected() === "following"}>
Expand Down
11 changes: 7 additions & 4 deletions src/components/members/UserProfileViewMobile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import type { Post } from "@lib/types";
import { ViewCard } from "@components/services/ViewCard";
import stripe from "@lib/stripe";
import { ViewUserPurchases } from "@components/posts/ViewUserPurchases";
import { ViewUserFavorites } from "@components/posts/ViewUserFavorites";

const lang = getLangFromUrl(new URL(window.location.href));
const t = useTranslations(lang);
Expand Down Expand Up @@ -200,7 +201,7 @@ export const UserProfileViewMobile: Component<Props> = (props: Props) => {

<div class="user-profile-tabs my-4 flex items-center justify-between border-b border-gray-300 pb-2">
<div class="">
<a
<a
id="user-profile-mobile-tab-purchases-link"
class="user-profile-mobile-tab-link mr-4 border-b-2 border-green-500 text-sm font-bold"
onClick={(e) => tabClick(e)}
Expand All @@ -214,15 +215,15 @@ export const UserProfileViewMobile: Component<Props> = (props: Props) => {
>
{t("menus.profile")}
</a>

{/* TODO: Add favorites and following tab when implemented

<a
id="user-profile-mobile-tab-favorites-link"
class="user-profile-mobile-tab-link mr-4 text-sm font-bold"
onClick={(e) => tabClick(e)}
>
{t("menus.favorites")}
</a>
{/* TODO: Add favorites and following tab when implemented
<a
id="user-profile-mobile-tab-following-link"
class="user-profile-mobile-tab-link mr-4 text-sm font-bold"
Expand Down Expand Up @@ -397,7 +398,9 @@ export const UserProfileViewMobile: Component<Props> = (props: Props) => {
</Show>

<Show when={tabSelected() === "favorites"}>
<p class="italic">{t("messages.comingSoon")}</p>
<div>
<ViewUserFavorites />
</div>
</Show>

<Show when={tabSelected() === "following"}>
Expand Down
30 changes: 15 additions & 15 deletions src/components/members/user/DownloadBtn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,24 @@ export const DownloadBtn: Component<Props> = (props: Props) => {
alert(t("messages.noUser")); //TODO: Change alert message
location.href = `/${lang}`;
} else {
console.log(data);
// console.log(data);
}
} catch (error) {
console.log(error);
}
};

onMount(async () => {
console.log("Item");
console.log(props.item);
// console.log("Item");
// console.log(props.item);
setSession(User?.session);
// await fetchUser(User?.session?.user.id!);
await getPurchasedItems();
});

const getPurchasedItems = async () => {
console.log("Session Info: ");
console.log(session());
// console.log("Session Info: ");
// console.log(session());
const { data: orders, error } = await supabase
.from("orders")
.select("*")
Expand All @@ -89,8 +89,8 @@ export const DownloadBtn: Component<Props> = (props: Props) => {
}
const orderedItemsIds = orders?.map((order) => order.order_number);

console.log("orders");
console.log(orders);
// console.log("orders");
// console.log(orders);

const { data: orderDetails, error: orderDetailsError } = await supabase
.from("order_details")
Expand All @@ -105,7 +105,7 @@ export const DownloadBtn: Component<Props> = (props: Props) => {
);
}
const products = orderDetails?.map((item) => item.product_id);
console.log(products);
// console.log(products);
if (products) {
setPurchasedItemsId(products);
}
Expand All @@ -126,18 +126,18 @@ export const DownloadBtn: Component<Props> = (props: Props) => {
return;
}
setPurchasedItems(productsInfo);
console.log("Purchased Items");
console.log(purchasedItems());
// console.log("Purchased Items");
// console.log(purchasedItems());

console.log("Checking purchased items");
// console.log("Checking purchased items");

if (props.item.id !== undefined) {
if (purchasedItemsId().includes(props.item.id)) {
for (const purchasedItem of purchasedItems()) {
if (purchasedItem.id === props.item.id) {
console.log(purchasedItem.resource_urls);
// console.log(purchasedItem.resource_urls);
setDownloadEnabled(true);
console.log(downloadEnabled());
// console.log(downloadEnabled());
break;
}
}
Expand All @@ -150,9 +150,9 @@ export const DownloadBtn: Component<Props> = (props: Props) => {
e.preventDefault();
e.stopPropagation();

console.log("Starting Download");
// console.log("Starting Download");

console.log(props.item.id);
// console.log(props.item.id);

if (props.item.id !== undefined) {
if (purchasedItemsId().includes(props.item.id)) {
Expand Down
Loading

0 comments on commit 0065ee0

Please sign in to comment.