-
Notifications
You must be signed in to change notification settings - Fork 280
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
Accounts, Part 3 #65
Merged
Merged
Accounts, Part 3 #65
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { Form } from "@remix-run/react"; | ||
import type { | ||
Customer, | ||
MailingAddress, | ||
} from "@shopify/hydrogen-ui-alpha/storefront-api-types"; | ||
import { Button, Link, Text } from "~/components"; | ||
|
||
export function AccountAddressBook({ | ||
customer, | ||
addresses, | ||
}: { | ||
customer: Customer; | ||
addresses: MailingAddress[]; | ||
}) { | ||
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">Address Book</h3> | ||
<div> | ||
{!addresses?.length && ( | ||
<Text className="mb-1" width="narrow" as="p" size="copy"> | ||
You haven'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> | ||
</div> | ||
</> | ||
); | ||
} | ||
|
||
function Address({ | ||
address, | ||
defaultAddress, | ||
}: { | ||
address: MailingAddress; | ||
defaultAddress?: boolean; | ||
}) { | ||
return ( | ||
<div className="lg:p-8 p-6 border border-gray-200 rounded flex flex-col"> | ||
{defaultAddress && ( | ||
<div className="mb-3 flex flex-row"> | ||
<span className="px-3 py-1 text-xs font-medium rounded-full bg-primary/20 text-primary/50"> | ||
Default | ||
</span> | ||
</div> | ||
)} | ||
<ul className="flex-1 flex-row"> | ||
{(address.firstName || address.lastName) && ( | ||
<li> | ||
{"" + | ||
(address.firstName && address.firstName + " ") + | ||
address?.lastName} | ||
</li> | ||
)} | ||
{address.formatted && | ||
address.formatted.map((line: string) => <li key={line}>{line}</li>)} | ||
</ul> | ||
|
||
<div className="flex flex-row font-medium mt-6"> | ||
<Link | ||
to={`address/${encodeURIComponent(address.id)}`} | ||
className="text-left underline text-sm" | ||
> | ||
Edit | ||
</Link> | ||
<Form action="address/delete" method="delete"> | ||
<input type="hidden" name="addressId" value={address.id} /> | ||
<button className="text-left text-primary/50 ml-6 text-sm"> | ||
Remove | ||
</button> | ||
</Form> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,11 @@ | ||
import {useParentRouteData} from './useRouteData'; | ||
import { useParentRouteData } from "./useRouteData"; | ||
|
||
import type { | ||
Cart, | ||
} from "@shopify/hydrogen-ui-alpha/storefront-api-types"; | ||
import type { Cart } from "@shopify/hydrogen-ui-alpha/storefront-api-types"; | ||
|
||
export function useCart(): Cart | undefined { | ||
const rootData = useParentRouteData('/'); | ||
const rootData = useParentRouteData("/"); | ||
|
||
if (rootData?.cart?._data) { | ||
return rootData?.cart?._data; | ||
} | ||
|
||
throw rootData?.cart | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,7 +121,8 @@ export default function Login() { | |
autoFocus | ||
onBlur={(event) => { | ||
setNativeEmailError( | ||
!event.currentTarget.validity.valid | ||
event.currentTarget.value.length && | ||
!event.currentTarget.validity.valid | ||
Comment on lines
+124
to
+125
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prevents the error from showing up if the user hasn't had a god-dang chance to fill it out yet!!! |
||
? "Invalid email address" | ||
: null | ||
); | ||
|
@@ -145,7 +146,10 @@ export default function Login() { | |
// eslint-disable-next-line jsx-a11y/no-autofocus | ||
autoFocus | ||
onBlur={(event) => { | ||
if (event.currentTarget.validity.valid) { | ||
if ( | ||
event.currentTarget.validity.valid || | ||
!event.currentTarget.value.length | ||
) { | ||
setNativePasswordError(null); | ||
} else { | ||
setNativePasswordError( | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This crashes the app if there is no cart present, so I removed it. We should reconsider whether we want a "magic" hook like this in H2.0.