Skip to content

Commit

Permalink
Updated claimSwagPack and orderSwagPack to pass in country
Browse files Browse the repository at this point in the history
  • Loading branch information
jessherlitz committed Aug 17, 2024
1 parent b5ad02f commit 3eab966
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export async function action({ request }: ActionFunctionArgs) {
addressState: data.addressState,
addressZip: data.addressZip,
studentId: user(session),
addressCountry: data.addressCountry,
});

return redirect(Route['/home/claim-swag-pack/confirmation']);
Expand All @@ -111,20 +112,22 @@ export default function ClaimSwagPack() {
</Modal.Header>

<Suspense fallback={<LoadingState />}>
<Await resolve={inventoryPromise}>
{(inventory) => {
return inventory > 0 ? (
<ClaimSwagPackForm />
) : (
<Modal.Description>
Unfortunately, we ran out of swag pack inventory. However, we're
restocking ASAP and you should be able to claim a pack in the
next 2-4 weeks. Sorry about any inconvenience and thank you for
your patience!
</Modal.Description>
);
}}
</Await>
{
<Await resolve={inventoryPromise}>
{(inventory) => {
return inventory > 0 ? (
<ClaimSwagPackForm />
) : (
<Modal.Description>
Unfortunately, we ran out of swag pack inventory. However,
we're restocking ASAP and you should be able to claim a pack
in the next 2-4 weeks. Sorry about any inconvenience and thank
you for your patience!
</Modal.Description>
);
}}
</Await>
}
</Suspense>
</>
);
Expand Down Expand Up @@ -171,15 +174,10 @@ function ClaimSwagPackForm() {
</Form.Field>

<Address.HalfGrid>
<Form.Field
error={errors.addressCity}
label="City"
labelFor={keys.addressCity}
required
>
<Address.City
id={keys.addressCity}
name={keys.addressCity}
<Form.Field label="Country" labelFor={keys.addressCountry} required>
<Address.Country
id={keys.addressCountry}
name={keys.addressCountry}
required
/>
</Form.Field>
Expand All @@ -197,6 +195,18 @@ function ClaimSwagPackForm() {
/>
</Form.Field>

<Form.Field
error={errors.addressCity}
label="City"
labelFor={keys.addressCity}
required
>
<Address.City
id={keys.addressCity}
name={keys.addressCity}
required
/>
</Form.Field>
<Form.Field
error={errors.addressZip}
label="ZIP Code"
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/modules/swag-pack/swag-pack.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export async function orderSwagPack(input: OrderSwagPackInput) {
shipping_address1: input.contact.address.line1,
shipping_address2: input.contact.address.line2,
shipping_city: input.contact.address.city,
shipping_country: 'US',
shipping_country: input.contact.address.country,
shipping_state: input.contact.address.state,
shipping_zip: input.contact.address.zip,
},
Expand Down Expand Up @@ -205,6 +205,7 @@ async function retrieveTokens(): Promise<OAuthTokens> {
// SwagUp would have an endpoint like POST /token/test to know if the
// token needed to be refreshed or not, but this is our current
// workaround.

const response = await fetch(`${SWAG_UP_API_URL}/accounts?limit=1`, {
headers: {
Authorization: `Bearer ${accessToken}`,
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/modules/swag-pack/swag-pack.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const ClaimSwagPackInput = z.object({
addressState: Address.shape.state,
addressZip: Address.shape.zip,
studentId: Student.shape.id,
addressCountry: Address.shape.country,
});

export type ClaimSwagPackInput = z.infer<typeof ClaimSwagPackInput>;
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export async function claimSwagPack({
addressState,
addressZip,
studentId,
addressCountry,
}: ClaimSwagPackInput) {
const student = await db
.selectFrom('students')
Expand All @@ -24,6 +25,7 @@ export async function claimSwagPack({
line2: addressLine2,
state: addressState,
zip: addressZip,
country: addressCountry,
},
email: student.email,
firstName: student.firstName,
Expand All @@ -39,6 +41,7 @@ export async function claimSwagPack({
addressLine2,
addressState,
addressZip,
addressCountry,
claimedSwagPackAt: new Date(),
swagUpOrderId: swagPackOrderId,
})
Expand Down
1 change: 1 addition & 0 deletions packages/types/src/domain/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const Address = z.object({
line2: z.string().trim().optional(),
state: z.string().trim().min(1),
zip: z.string().trim().min(1),
country: z.string().trim().length(2),
});

export type Address = z.infer<typeof Address>;
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/components/address.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const Address = ({ children }: PropsWithChildren) => {
<AddressContext.Provider
value={{ countryAbbreviation, setCountryAbbreviation }}
>
<div className="grid gap-4 @container">{children}</div>;
<div className="grid gap-4 @container">{children}</div>
</AddressContext.Provider>
);
};
Expand Down

0 comments on commit 3eab966

Please sign in to comment.