Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subject array display And Implementation #27

Merged
merged 17 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added signal-desktop-keyring.gpg
Binary file not shown.
48 changes: 46 additions & 2 deletions src/assets/categoryIcons/holiday.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
111 changes: 58 additions & 53 deletions src/components/posts/ClientViewProviderPosts.tsx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to update the productCategories forEach here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See Suggestions

Original file line number Diff line number Diff line change
Expand Up @@ -5,72 +5,77 @@ import supabase from "../../lib/supabaseClient";
import { ui } from "../../i18n/ui";
import type { uiObject } from "../../i18n/uiType";
import { getLangFromUrl, useTranslations } from "../../i18n/utils";
import stripe from "@lib/stripe";
import stripe from "@lib/stripe";

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

//get the categories from the language files so they translate with changes in the language picker
const values = ui[lang] as uiObject;
const productCategories = values.productCategoryInfo.categories;
const productCategories = values.subjectCategoryInfo.subjects;

interface ProviderPost {
user_id: string;
content: string;
id: number;
//TODO: update this to allow a list of Subjects
subject: string;
title: string;
seller_name: string;
major_municipality: string;
image_urls: string;
price: number;
price_id: string;
quantity: number;
product_id: string;
user_id: string;
content: string;
id: number;
image_url: string | undefined;
seller_img: string | undefined;
//TODO: update this to allow a list of Subjects
subject: Array<string>;
title: string;
seller_name: string;
major_municipality: string;
image_urls: string;
price: number;
price_id: string;
quantity: number;
product_id: string;
}

interface Props {
id: string | undefined;
id: string | undefined;
}

export const ClientViewProviderPosts: Component<Props> = (props) => {
const [posts, setPosts] = createSignal<Array<ProviderPost>>([]);
const [posts, setPosts] = createSignal<Array<ProviderPost>>([]);

createEffect(async () => {
const { data, error } = await supabase
.from("sellerposts")
.select("*")
.eq("seller_id", props.id);
if (!data) {
alert("No posts available.");
}
if (error) {
console.log("supabase error: " + error.message);
} else {
const newItems = await Promise.all(
data?.map(async (item) => {
productCategories.forEach((productCategories) => {
if (item.product_subject.toString() === productCategories.id) {
item.subject = productCategories.name;
}
});
delete item.product_subject;
createEffect(async () => {
const { data, error } = await supabase
.from("sellerposts")
.select("*")
.eq("seller_id", props.id);
if (!data) {
alert("No posts available.");
}
if (error) {
console.log("supabase error: " + error.message);
} else {
const newItems = await Promise.all(
data?.map(async (item) => {
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;

if (item.price_id !== null) {
const priceData = await stripe.prices.retrieve(item.price_id);
item.price = priceData.unit_amount! / 100;
}
return item;
}))
;
setPosts(data);
console.log("Posts")
console.log(posts())
}
});
return (
<div class="">
<ViewCard posts={posts()} />
</div>
);
if (item.price_id !== null) {
const priceData = await stripe.prices.retrieve(item.price_id);
item.price = priceData.unit_amount! / 100;
}
return item;
}),
);
setPosts(data);
console.log("Posts");
console.log(posts());
}
});
return (
<div class="">
<ViewCard posts={posts()} />
</div>
);
};
10 changes: 8 additions & 2 deletions src/components/posts/CreateNewPost.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ export const CreateNewPost: Component = () => {
const [selectedTaxCode, setSelectedTaxCode] =
createSignal<HTMLOptionElement>();

productCategoryData.subjects.map((item) =>
setSubjects([...subjects(), { id: Number(item.id), subject: item.name }]),
);
onMount(() => {
window.addEventListener("storage", (event) => {
if (event.key === "theme") {
Expand Down Expand Up @@ -191,11 +194,14 @@ export const CreateNewPost: Component = () => {
/^txcd_1.*/.test(taxCode.id) &&
//Not in our filter list
!Array.from(excludeTaxCodes).some((excludeTaxCode) =>
excludeTaxCode.test(taxCode.id)
excludeTaxCode.test(taxCode.id),
)
) {
let taxCodeOption = new Option(taxCode.name, taxCode.id);
taxCodeOption.setAttribute("data-description", taxCode.description);
taxCodeOption.setAttribute(
"data-description",
taxCode.description,
);
taxCodeOptions.push(taxCodeOption);
}
});
Expand Down
16 changes: 12 additions & 4 deletions src/components/posts/CreateStripeProductPrice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async function postStripeData(stripeData: FormData) {
});
const data = await response.json();
if (data.redirect) {
alert(data.message);
alert(data.message);
window.location.href = `/${lang}` + data.redirect;
}
return data;
Expand All @@ -35,7 +35,11 @@ interface Props {
export const CreateStripeProductPrice: Component<Props> = (props: Props) => {
const [stripeData, setStripeData] = createSignal<FormData>();
const [response] = createResource(stripeData, postStripeData);
async function createProduct(name: string, description: string, tax_code: string) {
async function createProduct(
name: string,
description: string,
tax_code: string,
) {
return stripe.products.create({
name: name,
description: description,
Expand All @@ -52,8 +56,12 @@ export const CreateStripeProductPrice: Component<Props> = (props: Props) => {
}

async function createPriceAndProduct() {
console.log("Stripe Tax Code: " + props.tax_code)
const product = await createProduct(props.name, props.description, props.tax_code);
console.log("Stripe Tax Code: " + props.tax_code);
const product = await createProduct(
props.name,
props.description,
props.tax_code,
);
const price = await createPrice(product, props.price);
const stripeData = new FormData();
stripeData.append("price_id", price.id);
Expand Down
Loading
Loading