Created
December 22, 2021 14:24
-
-
Save dshook/5268e8a9c6affa0416ba4c3c2a9c1740 to your computer and use it in GitHub Desktop.
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
/** ...imports... */ | |
export const AccountQuery = gql` | |
query exampleQuery($id: ID!) { | |
account(id: $id) { | |
id | |
name | |
addresses(type: [BUSINESS]) { | |
id | |
street | |
street2 | |
city | |
state | |
type | |
} | |
parentAccount { | |
id | |
} | |
} | |
} | |
`; | |
const StyledWrapper = styled.div` | |
margin: 10px auto; | |
background-color: ${palettes.gray[700]}; | |
`; | |
const AddressDisplay = styled.div` | |
text-align: left; | |
`; | |
export const GrowerTINEditContainer = () => { | |
const { accountId } = useParams<{ accountId: string }>(); | |
const { data, error, loading } = useQuery<ExampleQueryData, ExampleQueryVariables>(AccountQuery, { | |
variables: { id: accountId }, | |
}); | |
if (loading) { return <Loader />; } | |
if (error || !data?.account) { | |
throw new Error('Could not retrieve account'); | |
} | |
return ( | |
<StyledWrapper> | |
<SubComponent account={data?.account} /> | |
{data?.account.addresses.map(address => | |
<AddressDisplay | |
key={address.id} | |
address={address} | |
> | |
{`${address.street} ${address.city}, ${address.state}`} | |
</AddressDisplay> | |
)} | |
</StyledWrapper> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment