Skip to content

Commit

Permalink
Improve UI
Browse files Browse the repository at this point in the history
  • Loading branch information
Winston-Hsiao committed Nov 15, 2024
1 parent 1dce48b commit a37943c
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 25 deletions.
4 changes: 3 additions & 1 deletion frontend/src/components/listing/ListingPayment.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import CheckoutButton from "@/components/stripe/CheckoutButton";
import { formatPrice } from "@/lib/utils/formatNumber";

import { InventoryType } from "./types";

interface Props {
listingId: string;
stripeProductId: string;
priceAmount: number;
inventoryType: "finite" | "infinite" | "preorder";
inventoryType: InventoryType;
inventoryQuantity?: number;
preorderReleaseDate?: number;
preorderDepositAmount?: number;
Expand Down
4 changes: 1 addition & 3 deletions frontend/src/components/listing/ListingRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@ const ListingRenderer = ({ listing }: { listing: ListingResponse }) => {
listingId={listingId}
stripeProductId={stripeProductId}
priceAmount={priceAmount}
inventoryType={
inventoryType as "finite" | "infinite" | "preorder"
}
inventoryType={inventoryType as "finite" | "preorder"}
inventoryQuantity={inventoryQuantity || undefined}
preorderReleaseDate={preorderReleaseDate || undefined}
preorderDepositAmount={preorderDepositAmount || undefined}
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/components/listing/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ export type ListingResponse =
paths["/listings/{username}/{slug}"]["get"]["responses"][200]["content"]["application/json"];

export type Artifact = ListingResponse["artifacts"][number];

export type InventoryType = "finite" | "preorder";
9 changes: 6 additions & 3 deletions frontend/src/components/modals/CancelOrderModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import { useAuthentication } from "@/hooks/useAuth";
type Order =
paths["/orders/user-orders"]["get"]["responses"][200]["content"]["application/json"][0];

type RefundRequest =
paths["/stripe/refunds/{order_id}"]["put"]["requestBody"]["content"]["application/json"];

interface CancelOrderModalProps {
isOpen: boolean;
onOpenChange: (open: boolean) => void;
Expand All @@ -41,10 +44,10 @@ const CancelOrderModal: React.FC<CancelOrderModalProps> = ({

const MAX_REASON_LENGTH = 500;

const [cancellation, setCancellation] = useState({
payment_intent_id: order["stripe_payment_intent_id"] || "",
const [cancellation, setCancellation] = useState<RefundRequest>({
payment_intent_id: "",
cancel_reason: { reason: "", details: "" },
amount: order["amount"],
amount: 0,
});
const [customReason, setCustomReason] = useState("");

Expand Down
8 changes: 4 additions & 4 deletions frontend/src/components/pages/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -345,23 +345,23 @@ export const RenderProfile = (props: RenderProfileProps) => {
<Button
variant="outline"
asChild
className={`text-xs sm:text-sm px-2 sm:px-4 hover:bg-transparent ${value === "own" ? "border-0 bg-transparent hover:bg-transparent" : ""}`}
className={`text-xs sm:text-sm px-2 sm:px-4 hover:bg-gray-11 ${value === "own" ? "border" : ""}`}
>
<TabsTrigger
value="own"
className="data-[state=active]:bg-transparent"
className="data-[state=active]:bg-gray-3 text-gray-12"
>
Your Robot Listings
</TabsTrigger>
</Button>
<Button
variant="outline"
asChild
className={`text-xs sm:text-sm px-2 sm:px-4 hover:bg-transparent ${value === "upvoted" ? "border-0 bg-transparent hover:bg-transparent" : ""}`}
className={`text-xs sm:text-sm px-2 sm:px-4 hover:bg-gray-11 ${value === "upvoted" ? "border-0 bg-transparent hover:bg-transparent" : ""}`}
>
<TabsTrigger
value="upvoted"
className="data-[state=active]:bg-transparent"
className="data-[state=active]:bg-gray-3 text-gray-12"
>
Upvoted Robots
</TabsTrigger>
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/components/stripe/CheckoutButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ import { ApiError } from "@/lib/types/api";
import ROUTES from "@/lib/types/routes";
import { loadStripe } from "@stripe/stripe-js";

import { InventoryType } from "../listing/types";

interface Props {
listingId: string;
stripeProductId: string;
label?: string;
inventoryType?: "finite" | "infinite" | "preorder";
inventoryType?: InventoryType;
inventoryQuantity?: number;
}

Expand Down
16 changes: 9 additions & 7 deletions frontend/src/gen/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1579,10 +1579,10 @@ export interface components {
stripe_preorder_deposit_id?: string | null;
/**
* Inventory Type
* @default infinite
* @default finite
* @enum {string}
*/
inventory_type: "finite" | "infinite" | "preorder";
inventory_type: "finite" | "preorder";
/** Inventory Quantity */
inventory_quantity?: number | null;
/** Preorder Release Date */
Expand Down Expand Up @@ -1628,7 +1628,7 @@ export interface components {
/** Currency */
currency: string | null;
/** Inventory Type */
inventory_type: ("finite" | "infinite" | "preorder") | null;
inventory_type: ("finite" | "preorder") | null;
/** Inventory Quantity */
inventory_quantity: number | null;
};
Expand Down Expand Up @@ -1946,14 +1946,16 @@ export interface components {
stripe_deposit_price_id?: string | null;
/** Price Amount */
price_amount?: number | null;
/** Inventory Type */
inventory_type?: ("finite" | "infinite" | "preorder") | null;
/** Inventory Quantity */
inventory_quantity?: number | null;
/** Preorder Release Date */
preorder_release_date?: number | null;
/** Preorder Deposit Amount */
preorder_deposit_amount?: number | null;
/** Stripe Preorder Deposit Id */
stripe_preorder_deposit_id?: string | null;
/** Inventory Type */
inventory_type?: ("finite" | "preorder") | null;
/** Inventory Quantity */
inventory_quantity?: number | null;
};
/** UpdateOrderAddressRequest */
UpdateOrderAddressRequest: {
Expand Down
6 changes: 3 additions & 3 deletions store/app/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,9 @@ class Listing(StoreBaseModel):
currency: str = "usd"
stripe_product_id: str | None = None
stripe_price_id: str | None = None
preorder_deposit_amount: int | None = None
preorder_deposit_amount: int | None = None # in cents
stripe_preorder_deposit_id: str | None = None
inventory_type: Literal["finite", "infinite", "preorder"] = "infinite"
inventory_type: Literal["finite", "preorder"] = "finite"
inventory_quantity: int | None = None
preorder_release_date: int | None = None

Expand All @@ -408,7 +408,7 @@ def create(
stripe_price_id: str | None = None,
preorder_deposit_amount: int | None = None,
stripe_preorder_deposit_id: str | None = None,
inventory_type: Literal["finite", "infinite", "preorder"] = "infinite",
inventory_type: Literal["finite", "preorder"] = "finite",
inventory_quantity: int | None = None,
preorder_release_date: int | None = None,
) -> Self:
Expand Down
4 changes: 2 additions & 2 deletions store/app/routers/listings.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class ListingInfoResponse(BaseModel):
user_vote: bool | None
price_amount: int | None
currency: str | None
inventory_type: Literal["finite", "infinite", "preorder"] | None
inventory_type: Literal["finite", "preorder"] | None
inventory_quantity: int | None


Expand Down Expand Up @@ -393,7 +393,7 @@ class UpdateListingRequest(BaseModel):
preorder_release_date: int | None = None
preorder_deposit_amount: int | None = None
stripe_preorder_deposit_id: str | None = None
inventory_type: Literal["finite", "infinite", "preorder"] | None = None
inventory_type: Literal["finite", "preorder"] | None = None
inventory_quantity: int | None = None


Expand Down
2 changes: 1 addition & 1 deletion store/app/routers/stripe.py
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ async def create_listing_product(
description: str,
price_amount: int,
currency: str,
inventory_type: Literal["finite", "infinite", "preorder"],
inventory_type: Literal["finite", "preorder"],
inventory_quantity: int | None,
preorder_release_date: int | None,
preorder_deposit_amount: int | None,
Expand Down

0 comments on commit a37943c

Please sign in to comment.