Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/Weaverse/pilot into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
hta218 committed Oct 14, 2024
2 parents 985217e + bb67549 commit a9b075a
Show file tree
Hide file tree
Showing 19 changed files with 1,040 additions and 477 deletions.
15 changes: 15 additions & 0 deletions app/components/icons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,21 @@ export function IconSignIn(props: IconProps) {
);
}

export function IconSignOut(props: IconProps) {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
width="32"
height="32"
viewBox="0 0 256 256"
fill="currentColor"
{...props}
>
<path d="M120,216a8,8,0,0,1-8,8H48a8,8,0,0,1-8-8V40a8,8,0,0,1,8-8h64a8,8,0,0,1,0,16H56V208h56A8,8,0,0,1,120,216Zm109.66-93.66-40-40a8,8,0,0,0-11.32,11.32L204.69,120H112a8,8,0,0,0,0,16h92.69l-26.35,26.34a8,8,0,0,0,11.32,11.32l40-40A8,8,0,0,0,229.66,122.34Z"></path>
</svg>
);
}

export function IconList(props: IconProps) {
return (
<svg
Expand Down
15 changes: 15 additions & 0 deletions app/graphql/customer-account/customer-order-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ export const CUSTOMER_ORDER_QUERY = `#graphql
currencyCode
}
fragment DiscountApplication on DiscountApplication {
... on AutomaticDiscountApplication {
title
}
... on DiscountCodeApplication {
code
}
value {
__typename
... on MoneyV2 {
Expand All @@ -22,6 +28,12 @@ export const CUSTOMER_ORDER_QUERY = `#graphql
price {
...OrderMoney
}
currentTotalPrice {
...OrderMoney
}
totalPrice {
...OrderMoney
}
discountAllocations {
allocatedAmount {
...OrderMoney
Expand Down Expand Up @@ -61,6 +73,9 @@ export const CUSTOMER_ORDER_QUERY = `#graphql
subtotal {
...OrderMoney
}
totalShipping {
...OrderMoney
}
shippingAddress {
name
formatted(withName: true)
Expand Down
104 changes: 91 additions & 13 deletions app/lib/judgeme.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { json } from "@remix-run/server-runtime";
import type { WeaverseClient } from "@weaverse/hydrogen";

type JudgemeProductData = {
Expand All @@ -7,17 +8,36 @@ type JudgemeProductData = {
};
};

type JudgemeReviewsData = {
reviews: {
rating: number;
type JudgemeReviewType = {
id: string;
title: string;
body: string;
rating: number;
reviewer: {
id: number;
email: string;
name: string;
phone: string;
};
pictures: {
urls: {
original: string;
small: string;
compact: string;
huge: string;
};
}[];
};

type JudgemeReviewsData = {
reviews: JudgemeReviewType[];
};

async function getInternalIdByHandle(
api_token: string,
shop_domain: string,
handle: string,
weaverseClient: WeaverseClient,
weaverseClient: WeaverseClient
) {
let api = `https://judge.me/api/v1/products/-1?${new URLSearchParams({
api_token,
Expand All @@ -32,26 +52,29 @@ export let getJudgemeReviews = async (
api_token: string,
shop_domain: string,
handle: string,
weaverse: WeaverseClient,
weaverse: WeaverseClient
) => {
const defaultData = {
rating: 0,
reviewNumber: 0,
reviews: [],
};
if (!api_token) {
return {
error: "Missing JUDGEME_PRIVATE_API_TOKEN",
};
return defaultData;
}
let internalId = await getInternalIdByHandle(
api_token,
shop_domain,
handle,
weaverse,
weaverse
);
if (internalId) {
let data = (await weaverse.fetchWithCache(
`https://judge.me/api/v1/reviews?${new URLSearchParams({
api_token,
shop_domain,
product_id: internalId,
})}`,
})}`
)) as JudgemeReviewsData;
let reviews = data.reviews;
let rating =
Expand All @@ -60,9 +83,64 @@ export let getJudgemeReviews = async (
return {
rating,
reviewNumber: reviews.length,
reviews,
};
}
return {
rating: 0,
};
return defaultData;
};

const endpoint = "https://judge.me/api/v1/reviews";
export let createJudgemeReview = async (
api_token: string,
shop_domain: string,
formData: FormData
) => {
if (!api_token) {
return {
error: "Missing JUDGEME_PRIVATE_API_TOKEN",
};
}
const body = formDataToObject(formData);
const url = new URL(endpoint);
url.searchParams.append("api_token", api_token);
url.searchParams.append("shop_domain", shop_domain);
const payload = JSON.stringify({
shop_domain,
platform: "shopify",
...body,
});

try {
const response = await fetch(endpoint, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: payload,
});
const status = response.status;
if (response.ok) {
return { success: true, status };
}
return {
success: false,
message: "Something went wrong! Please try again.",
status,
};
} catch (error) {
console.error(error);
return {
success: false,
message: "Something went wrong! Please try again.",
status: 500,
};
}
};

function formDataToObject(formData: FormData) {
const data: any = {};
for (const [key, value] of formData.entries()) {
data[key] = value;
}
return data;
}
72 changes: 34 additions & 38 deletions app/modules/account-address-book.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Form } from "@remix-run/react";
import type { CustomerAddress } from "@shopify/hydrogen/customer-account-api-types";
import type { CustomerDetailsFragment } from "customer-accountapi.generated";
import Button from "~/components/button";
import { Link } from "~/components/link";
import { Button } from "~/modules/button";
import { Text } from "~/modules/text";
import { Text } from "./text";

export function AccountAddressBook({
customer,
Expand All @@ -13,39 +13,33 @@ export function AccountAddressBook({
addresses: CustomerAddress[];
}) {
return (
<>
<div className="grid w-full gap-4 p-4 py-6 md:gap-8 md:p-8 lg:p-12">
<h3 className="font-bold text-lg">Address Book</h3>
<div>
{!addresses?.length && (
<Text className="mb-1" width="narrow" as="p" size="copy">
You haven&apos;t saved any addresses yet.
</Text>
)}
<div className="w-48">
<Button
to="address/add"
className="mt-2 text-sm w-full mb-6"
variant="secondary"
>
Add an Address
</Button>
</div>
{Boolean(addresses?.length) && (
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-6">
{customer.defaultAddress && (
<Address address={customer.defaultAddress} defaultAddress />
)}
{addresses
.filter((address) => address.id !== customer.defaultAddress?.id)
.map((address) => (
<Address key={address.id} address={address} />
))}
</div>
)}
<div className="space-y-4">
<div className="font-bold">Address Book</div>
<div>
{!addresses?.length && (
<Text className="mb-1" size="fine" width="narrow" as="p">
You haven&apos;t saved any addresses yet.
</Text>
)}
<div className="">
<Button link="address/add" className="mb-5" variant="primary">
Add an Address
</Button>
</div>
{Boolean(addresses?.length) && (
<div className="grid grid-cols-1 md:grid-cols-2 gap-5">
{customer.defaultAddress && (
<Address address={customer.defaultAddress} defaultAddress />
)}
{addresses
.filter((address) => address.id !== customer.defaultAddress?.id)
.map((address) => (
<Address key={address.id} address={address} />
))}
</div>
)}
</div>
</>
</div>
);
}

Expand All @@ -57,18 +51,20 @@ function Address({
defaultAddress?: boolean;
}) {
return (
<div className="lg:p-8 p-6 border border-gray-200 rounded flex flex-col">
<div className="p-5 border border-[#B7B7B7] rounded-sm flex flex-col">
{defaultAddress && (
<div className="mb-3 flex flex-row">
<span className="px-3 py-1 text-xs font-medium rounded-full bg-background/20 text-body/50">
<span className="px-3 py-1 text-xs font-medium border text-body/50">
Default
</span>
</div>
)}
<ul className="flex-1 flex-row">
{(address.firstName || address.lastName) && (
<li>
{`${address.firstName && `${address.firstName} `}${address?.lastName}`}
<li className="mb-2">
{`${address.firstName && `${address.firstName} `}${
address?.lastName
}`}
</li>
)}
{address.formatted?.map((line: string) => (
Expand All @@ -79,7 +75,7 @@ function Address({
<div className="flex flex-row font-medium mt-6 items-baseline">
<Link
to={`/account/address/${encodeURIComponent(address.id)}`}
className="text-left underline text-sm"
className="text-left underline text-body/50"
prefetch="intent"
>
Edit
Expand Down
47 changes: 20 additions & 27 deletions app/modules/account-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,29 @@ export function AccountDetails({
customer: CustomerDetailsFragment;
}) {
const { firstName, lastName, emailAddress, phoneNumber } = customer;

const fullName = `${firstName || ""} ${lastName || ""}`.trim();
return (
<>
<div className="grid w-full gap-4 p-4 py-6 md:gap-8 md:p-8 lg:p-12">
<h3 className="font-bold text-lead">Account Details</h3>
<div className="lg:p-8 p-6 border border-gray-200 rounded">
<div className="flex">
<h3 className="font-bold text-base flex-1">Profile</h3>
<Link
prefetch="intent"
className="underline text-sm font-normal"
to="/account/edit"
>
Edit
</Link>
</div>
<div className="mt-4 text-sm text-body/50">Name</div>
<p className="mt-1">
{firstName || lastName
? (firstName ? `${firstName} ` : "") + lastName
: "Add name"}{" "}
</p>
<div className="space-y-4">
<div className="font-bold">Account</div>
<div className="p-5 border border-[#B7B7B7] rounded-sm">
<div className="text-body/50">Name</div>
<p className="mt-1">{fullName || "N/A"}</p>

<div className="mt-4 text-sm text-body/50">Phone number</div>
<p className="mt-1">{phoneNumber?.phoneNumber ?? "N/A"}</p>
<div className="mt-4 text-body/50">Phone number</div>
<p className="mt-1">{phoneNumber?.phoneNumber ?? "N/A"}</p>

<div className="mt-4 text-sm text-body/50">Email address</div>
<p className="mt-1">{emailAddress?.emailAddress ?? "N/A"}</p>
</div>
<div className="mt-4 text-body/50">Email address</div>
<p className="mt-1">{emailAddress?.emailAddress ?? "N/A"}</p>
<p className="mt-3">
<Link
prefetch="intent"
className="underline font-normal text-body/50"
to="/account/edit"
>
Edit
</Link>
</p>
</div>
</>
</div>
);
}
9 changes: 7 additions & 2 deletions app/modules/icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ export function IconStar(props: IconProps) {
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
fill="currentColor"
fill="none"
{...props}
>
<polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2" />
Expand All @@ -516,7 +516,12 @@ export function IconStarHalf(props: IconProps) {
strokeLinejoin="round"
{...props}
>
<path d="M12 17.8 5.8 21 7 14.1 2 9.3l7-1L12 2" />
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
<path
d="M12 1a.993 .993 0 0 1 .823 .443l.067 .116l2.852 5.781l6.38 .925c.741 .108 1.08 .94 .703 1.526l-.07 .095l-.078 .086l-4.624 4.499l1.09 6.355a1.001 1.001 0 0 1 -1.249 1.135l-.101 -.035l-.101 -.046l-5.693 -3l-5.706 3c-.105 .055 -.212 .09 -.32 .106l-.106 .01a1.003 1.003 0 0 1 -1.038 -1.06l.013 -.11l1.09 -6.355l-4.623 -4.5a1.001 1.001 0 0 1 .328 -1.647l.113 -.036l.114 -.023l6.379 -.925l2.853 -5.78a.968 .968 0 0 1 .904 -.56zm0 3.274v12.476a1 1 0 0 1 .239 .029l.115 .036l.112 .05l4.363 2.299l-.836 -4.873a1 1 0 0 1 .136 -.696l.07 -.099l.082 -.09l3.546 -3.453l-4.891 -.708a1 1 0 0 1 -.62 -.344l-.073 -.097l-.06 -.106l-2.183 -4.424z"
strokeWidth="0"
fill="currentColor"
/>
</svg>
);
}
Expand Down
Loading

0 comments on commit a9b075a

Please sign in to comment.