This repository has been archived by the owner on Nov 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Add ability to see members by product
- Loading branch information
1 parent
bc1ac53
commit 47aedb3
Showing
14 changed files
with
684 additions
and
5 deletions.
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
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
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { Stack, Typography } from '@mui/material'; | ||
import MUIDataTable from 'mui-datatables'; | ||
import { GetMembersByProductQuery, useGetMembersByProductQuery } from '~/generated/graphql'; | ||
import LoadingButton from '../LoadingButton'; | ||
|
||
const columns = [ | ||
'First Name', | ||
'Last Name', | ||
'Student ID', | ||
'Food Preference', | ||
'Variant', | ||
'Consumed At', | ||
'Paid At', | ||
]; | ||
|
||
const options = { | ||
filterType: 'checkbox', | ||
}; | ||
|
||
function createDataItem(item: GetMembersByProductQuery['getMembersByProduct'][number]) { | ||
return [ | ||
item.member.first_name, | ||
item.member.last_name, | ||
item.member.student_id, | ||
item.member.food_preference, | ||
item.userInventoryItem.variant, | ||
item.userInventoryItem.consumedAt, | ||
item.userInventoryItem.paidAt, | ||
]; | ||
} | ||
|
||
export default function MembersByProduct({ productId }: { productId: string }) { | ||
const { data: graphqlData, refetch } = useGetMembersByProductQuery({ | ||
variables: { | ||
productId, | ||
}, | ||
}); | ||
const data = graphqlData?.getMembersByProduct.map(createDataItem) ?? [ | ||
'Loading...', | ||
]; | ||
return ( | ||
<Stack spacing={1}> | ||
<h2>Members by product</h2> | ||
<Typography> | ||
Total purchases: | ||
{' '} | ||
{graphqlData?.getMembersByProduct.length} | ||
</Typography> | ||
<LoadingButton onClick={async () => { | ||
await refetch(); | ||
}} | ||
> | ||
Reload data | ||
</LoadingButton> | ||
<MUIDataTable | ||
title="Members with this item in their inventory" | ||
data={data} | ||
columns={columns} | ||
options={options} | ||
/> | ||
</Stack> | ||
); | ||
} |
Oops, something went wrong.