Skip to content

Commit

Permalink
Merge pull request #47 from datagrove/userProfileStyles
Browse files Browse the repository at this point in the history
User profile styles
  • Loading branch information
r-southworth authored May 24, 2024
2 parents 3e9c22b + 5d92938 commit 19c84a9
Show file tree
Hide file tree
Showing 20 changed files with 2,642 additions and 762 deletions.
5 changes: 0 additions & 5 deletions src/components/posts/FullPostView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import SocialModal from "./SocialModal";
import { AddToCart } from "@components/common/cart/AddToCartButton";
import { Quantity } from "@components/common/cart/Quantity";
import type { AuthSession } from "@supabase/supabase-js";
import { DownloadBtn } from "@components/common/cart/DownloadBtn";

import stripe from "@lib/stripe";

Expand Down Expand Up @@ -746,10 +745,6 @@ export const ViewFullPost: Component<Props> = (props) => {
item={{ ...post()!, quantity: 1 }}
buttonClick={resetQuantity}
/>
<DownloadBtn
item={{ ...post() }}
buttonClick={resetQuantity}
/>
</div>
<div class="my-4 flex items-center justify-center">
<button class="btn-primary md:hidden">
Expand Down
42 changes: 0 additions & 42 deletions src/components/posts/MobileFullPostView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import type { uiObject } from "../../i18n/uiType";
import { getLangFromUrl, useTranslations } from "../../i18n/utils";
import { AddToCart } from "@components/common/cart/AddToCartButton";
import { Quantity } from "@components/common/cart/Quantity";
import { DownloadBtn } from "@components/common/cart/DownloadBtn";
import { FreeDownloadButton } from "@components/common/cart/FreeDownloadButton";
import stripe from "@lib/stripe"


Expand Down Expand Up @@ -284,44 +282,6 @@ export const MobileViewFullPost: Component<Props> = (props) => {
window.location.href = "#qa";
}

// if(currLinkID === "detailsLink") {
// if(detailsDiv.classList.contains("hidden")) {
// detailsDiv.classList.remove("hidden");
// detailsDiv.classList.add("inline");

// detailsArrow.classList.add("rotate");

// window.location.href="#details";
// }
// } else if(currLinkID === "descriptionLink") {
// if(descriptionDiv.classList.contains("hidden")) {
// descriptionDiv.classList.remove("hidden");
// descriptionDiv.classList.add("inline");

// descriptionArrow.classList.add("rotate");

// window.location.href="#description";
// }
// } else if(currLinkID === "reviewsLink") {
// if(reviewsDiv.classList.contains("hidden")) {
// reviewsDiv.classList.remove("hidden");
// reviewsDiv.classList.add("inline");

// reviewsArrow.classList.add("rotate");

// window.location.href="#reviews";
// }
// } else if(currLinkID === "qaLink") {
// if(qaDiv.classList.contains("hidden")) {
// qaDiv.classList.remove("hidden");
// qaDiv.classList.add("inline");

// qaArrow.classList.add("rotate");

// window.location.href="#qa";
// }
// }

let sectionID = currLinkID.slice(0, -4);
let jumpToSection = `#${sectionID}`;
window.location.href = jumpToSection;
Expand Down Expand Up @@ -608,13 +568,11 @@ export const MobileViewFullPost: Component<Props> = (props) => {
<div class="my-2 flex justify-between">
<Quantity quantity={1} updateQuantity={updateQuantity} />
<div class="ml-4 w-full">
{/* TODO: Add FreeDownloadButton component if resource is free */}

<AddToCart
item={{ ...post()!, quantity: 1 }}
buttonClick={resetQuantity}
/>
<DownloadBtn item={{ ...post(), quantity: 1 }} />
</div>
</div>
</div>
Expand Down
208 changes: 208 additions & 0 deletions src/components/posts/ViewClientPurchases.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
import type { Component } from "solid-js";
import type { Client } from "@lib/types";
import stripe from "@lib/stripe";
import { createSignal, createEffect, Show, onMount } from "solid-js";
import supabase from "../../lib/supabaseClient.tsx";
import { getLangFromUrl, useTranslations } from "../../i18n/utils.ts";
import { ui } from "../../i18n/ui";
import type { uiObject } from "../../i18n/uiType";
import type { AuthSession } from "@supabase/supabase-js";
import { ViewPurchaseCard } from "@components/services/ViewPurchaseCard.tsx";

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

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

const { data: User, error: UserError } = await supabase.auth.getSession();

export const ViewClientPurchases: Component = () => {
const [session, setSession] = createSignal<AuthSession | null>(null);
const [client, setClient] = createSignal<Client>();
const [purchasedItems, setPurchasedItems] = createSignal<Array<any>>([]);

if (UserError) {
console.log("User Error: " + UserError.message);
} else {
setSession(User.session);
}

onMount(async () => {
setSession(User?.session);
await fetchClient(User?.session?.user.id!);
await getPurchasedItems();
});

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)
.eq("order_status", true);
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, order_number")
.in("order_number", orderedItemsIds);
if (orderDetailsError) {
console.log(
"Order Details Error: " +
orderDetailsError.code +
" " +
orderDetailsError.message
);
}

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 products = orderDetails?.map((item) => item.product_id);
if (products !== undefined) {
const { data: productsInfo, error: productsInfoError } =
await supabase
.from("seller_post")
.select("*")
.in("id", products);
if (productsInfoError) {
console.log(
"Products Info Error: " +
productsInfoError.code +
" " +
productsInfoError.message
);
return;
} 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;
})
);

itemsOrdered?.sort(function (a, b) {
return b.purchaseDate.localeCompare(a.purchaseDate);
});

console.log(itemsOrdered)
console.log(newItems)

const newItemsDates = newItems.map((item) => {
const orderInfo = itemsOrdered?.find(
(order) => (order.product_id === item.id)
);
if (orderInfo){
return {
...item,
purchaseDate: orderInfo.purchaseDate
}
}
return item;
});

console.log(newItemsDates)

setPurchasedItems(newItemsDates);
console.log(purchasedItems());
}
}
};

const fetchClient = async (user_id: string) => {
try {
const { data, error } = await supabase
.from("clientview")
.select("*")
.eq("user_id", user_id);

if (error) {
console.log(error);
} else if (data[0] === undefined) {
alert(t("messages.noClient")); //TODO: Change alert message
location.href = `/${lang}`;
} else {
console.log(data);
setClient(data[0]);
console.log(client());
}
} catch (error) {
console.log(error);
}
};


return (
<div>
<div id="Cards">
<ViewPurchaseCard posts={purchasedItems()} />
</div>
</div>
);
};
16 changes: 1 addition & 15 deletions src/components/services/ViewCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import SocialModal from "../posts/SocialModal";
import { AddToCart } from "../common/cart/AddToCartButton";
import { Quantity } from "@components/common/cart/Quantity";
import type { AuthSession } from "@supabase/supabase-js";
import { DownloadBtn } from "@components/common/cart/DownloadBtn";
import { DownloadBtn } from "@components/users/client/DownloadBtn";

const lang = getLangFromUrl(new URL(window.location.href));
const t = useTranslations(lang);
Expand Down Expand Up @@ -362,20 +362,6 @@ export const ViewCard: Component<Props> = (props) => {
buttonClick={resetQuantity}
/>
</Show>
{/* <Quantity quantity={1} updateQuantity={updateQuantity}/> */}

{/* <Show
when={
(session() === null ||
session()?.user.id !==
post.user_id) &&
post.price === undefined
}
>
<DownloadBtn
item={{ ...post, quantity: 1 }}
/>
</Show>

<div class="relative col-span-1 flex w-full justify-end align-top">
<div class="inline-block">
Expand Down
Loading

0 comments on commit 19c84a9

Please sign in to comment.