This repository has been archived by the owner on Aug 6, 2024. It is now read-only.
generated from abir-taheer/quicker-picker-upper
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #562 from stuysu/restyled/promoted-club
Restyle Add promoted club frontend features
- Loading branch information
Showing
6 changed files
with
320 additions
and
329 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,58 @@ | ||
import React from "react"; | ||
import Card from "@material-ui/core/Card"; | ||
import { makeStyles } from "@material-ui/core/styles"; | ||
import List from "@material-ui/core/List"; | ||
import ListItem from "@material-ui/core/ListItem"; | ||
import ListItemAvatar from "@material-ui/core/ListItemAvatar"; | ||
import ListItemSecondaryAction from "@material-ui/core/ListItemSecondaryAction"; | ||
import Avatar from "@material-ui/core/Avatar"; | ||
import ListItemText from "@material-ui/core/ListItemText"; | ||
import UnstyledLink from "../../ui/UnstyledLink"; | ||
import { Typography } from "@material-ui/core"; | ||
import PromotedClubDeleteButton from "./PromotedClubDeleteButton"; | ||
|
||
const useStyles = makeStyles({ | ||
clubCard: { | ||
position: "relative", | ||
width: "100%", | ||
margin: "0.5rem 0" | ||
}, | ||
orgHeading: { | ||
cursor: "pointer", | ||
"&:hover": { | ||
opacity: 0.9 | ||
} | ||
}, | ||
content: { | ||
padding: "0 1rem" | ||
} | ||
}); | ||
|
||
const PromotedClubCard = ({ | ||
id, | ||
blurb, | ||
organization, | ||
showDelete = false, | ||
refetch = () => {} | ||
}) => { | ||
const classes = useStyles(); | ||
|
||
return ( | ||
<Card variant={"outlined"} className={classes.clubCard}> | ||
<List> | ||
<UnstyledLink to={`/${organization.url}`}> | ||
<ListItem className={classes.orgHeading}> | ||
<ListItemAvatar> | ||
<Avatar alt={organization?.name} src={organization?.charter?.picture?.thumbnail} /> | ||
</ListItemAvatar> | ||
<ListItemText primary={organization?.name}/> | ||
</ListItem> | ||
</UnstyledLink> | ||
{showDelete && ( | ||
<ListItemSecondaryAction> | ||
<PromotedClubDeleteButton promotionId={id} refetch={refetch}/> | ||
</ListItemSecondaryAction> | ||
)} | ||
</List> | ||
<div className={classes.content}> | ||
<Typography paragraph> | ||
{blurb} | ||
</Typography> | ||
</div> | ||
</Card> | ||
); | ||
}; | ||
|
||
export default PromotedClubCard; | ||
import React from "react"; | ||
import Card from "@material-ui/core/Card"; | ||
import { makeStyles } from "@material-ui/core/styles"; | ||
import List from "@material-ui/core/List"; | ||
import ListItem from "@material-ui/core/ListItem"; | ||
import ListItemAvatar from "@material-ui/core/ListItemAvatar"; | ||
import ListItemSecondaryAction from "@material-ui/core/ListItemSecondaryAction"; | ||
import Avatar from "@material-ui/core/Avatar"; | ||
import ListItemText from "@material-ui/core/ListItemText"; | ||
import UnstyledLink from "../../ui/UnstyledLink"; | ||
import { Typography } from "@material-ui/core"; | ||
import PromotedClubDeleteButton from "./PromotedClubDeleteButton"; | ||
|
||
const useStyles = makeStyles({ | ||
clubCard: { | ||
position: "relative", | ||
width: "100%", | ||
margin: "0.5rem 0" | ||
}, | ||
orgHeading: { | ||
cursor: "pointer", | ||
"&:hover": { | ||
opacity: 0.9 | ||
} | ||
}, | ||
content: { | ||
padding: "0 1rem" | ||
} | ||
}); | ||
|
||
const PromotedClubCard = ({ id, blurb, organization, showDelete = false, refetch = () => {} }) => { | ||
const classes = useStyles(); | ||
|
||
return ( | ||
<Card variant={"outlined"} className={classes.clubCard}> | ||
<List> | ||
<UnstyledLink to={`/${organization.url}`}> | ||
<ListItem className={classes.orgHeading}> | ||
<ListItemAvatar> | ||
<Avatar alt={organization?.name} src={organization?.charter?.picture?.thumbnail} /> | ||
</ListItemAvatar> | ||
<ListItemText primary={organization?.name} /> | ||
</ListItem> | ||
</UnstyledLink> | ||
{showDelete && ( | ||
<ListItemSecondaryAction> | ||
<PromotedClubDeleteButton promotionId={id} refetch={refetch} /> | ||
</ListItemSecondaryAction> | ||
)} | ||
</List> | ||
<div className={classes.content}> | ||
<Typography paragraph>{blurb}</Typography> | ||
</div> | ||
</Card> | ||
); | ||
}; | ||
|
||
export default PromotedClubCard; |
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,54 +1,54 @@ | ||
import React from "react"; | ||
import { IconButton } from "@material-ui/core"; | ||
import { Menu as MenuIcon } from "@material-ui/icons"; | ||
import Menu from "@material-ui/core/Menu"; | ||
import MenuItem from "@material-ui/core/MenuItem"; | ||
import { gql, useMutation } from "@apollo/client"; | ||
|
||
const MUTATION = gql` | ||
mutation ($promotionId: Int!){ | ||
deletePromotedClub(promotedClubId: $promotionId) | ||
} | ||
`; | ||
|
||
const PromotedClubDeleteButton = ({ promotionId, refetch }) => { | ||
const [deletePromotion] = useMutation(MUTATION, { | ||
variables: { promotionId }, | ||
update(cache){ | ||
cache.reset(); | ||
refetch(); | ||
} | ||
}); | ||
|
||
const [anchorEl, setAnchorEl] = React.useState(null); | ||
|
||
const handleDelete = () => { | ||
setAnchorEl(null); | ||
if (window.confirm("Are you sure you want to delete this promotion? This is irreversible.")) { | ||
deletePromotion().catch(er => alert("There was an issue: " + er.message)); | ||
} | ||
}; | ||
|
||
const handleClose = () => { | ||
setAnchorEl(null); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<IconButton onClick={ev => setAnchorEl(ev.target)}> | ||
<MenuIcon /> | ||
</IconButton> | ||
<Menu | ||
anchorEl={anchorEl} | ||
keepMounted | ||
open={Boolean(anchorEl)} | ||
onClose={handleClose} | ||
transformOrigin={"center top"} | ||
> | ||
<MenuItem onClick={handleDelete}>Delete</MenuItem> | ||
</Menu> | ||
</div> | ||
); | ||
}; | ||
|
||
export default PromotedClubDeleteButton; | ||
import React from "react"; | ||
import { IconButton } from "@material-ui/core"; | ||
import { Menu as MenuIcon } from "@material-ui/icons"; | ||
import Menu from "@material-ui/core/Menu"; | ||
import MenuItem from "@material-ui/core/MenuItem"; | ||
import { gql, useMutation } from "@apollo/client"; | ||
|
||
const MUTATION = gql` | ||
mutation ($promotionId: Int!) { | ||
deletePromotedClub(promotedClubId: $promotionId) | ||
} | ||
`; | ||
|
||
const PromotedClubDeleteButton = ({ promotionId, refetch }) => { | ||
const [deletePromotion] = useMutation(MUTATION, { | ||
variables: { promotionId }, | ||
update(cache) { | ||
cache.reset(); | ||
refetch(); | ||
} | ||
}); | ||
|
||
const [anchorEl, setAnchorEl] = React.useState(null); | ||
|
||
const handleDelete = () => { | ||
setAnchorEl(null); | ||
if (window.confirm("Are you sure you want to delete this promotion? This is irreversible.")) { | ||
deletePromotion().catch(er => alert("There was an issue: " + er.message)); | ||
} | ||
}; | ||
|
||
const handleClose = () => { | ||
setAnchorEl(null); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<IconButton onClick={ev => setAnchorEl(ev.target)}> | ||
<MenuIcon /> | ||
</IconButton> | ||
<Menu | ||
anchorEl={anchorEl} | ||
keepMounted | ||
open={Boolean(anchorEl)} | ||
onClose={handleClose} | ||
transformOrigin={"center top"} | ||
> | ||
<MenuItem onClick={handleDelete}>Delete</MenuItem> | ||
</Menu> | ||
</div> | ||
); | ||
}; | ||
|
||
export default PromotedClubDeleteButton; |
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,54 +1,57 @@ | ||
import React from 'react'; | ||
import { Typography, TextField }from "@material-ui/core"; | ||
import Autocomplete from "@material-ui/lab/Autocomplete"; | ||
import { gql, useQuery } from "@apollo/client"; | ||
|
||
const QUERY = gql` | ||
query FindOrganization($keyword: String!){ | ||
organizations(keyword: $keyword, limit: 15){ | ||
id | ||
name | ||
} | ||
} | ||
` | ||
|
||
const OrganizationPicker = ({ setOrgId }) => { | ||
const [orgName, setOrgName] = React.useState(""); | ||
const [keyword, setKeyword] = React.useState(""); | ||
const {data, loading} = useQuery(QUERY, { | ||
variables: {keyword} | ||
}); | ||
const options = data === undefined ? [] : data.organizations; | ||
return ( | ||
<div> | ||
<Typography variant={"h5"}>Currently Selected Club: </Typography> | ||
<div> | ||
{orgName === "" ? <Autocomplete | ||
options={options} | ||
value={null} | ||
getOptionLabel={_ => ""} | ||
renderOption={option => <span>{option.name}</span>} | ||
onChange={(ev, newvalue) => { | ||
setOrgName(newvalue.name); | ||
setOrgId(newvalue.id); | ||
}} | ||
loading={loading} | ||
filterOptions={f => f} | ||
renderInput={params => ( | ||
<TextField | ||
{...params} | ||
required = {true} | ||
label = "Find Organization" | ||
variant = "outlined" | ||
value = {keyword} | ||
onChange = {ev => setKeyword(ev.target.value)} | ||
/> | ||
)} | ||
/> : | ||
<Typography variant={"h5"}>{orgName}</Typography>} | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default OrganizationPicker; | ||
import React from "react"; | ||
import { Typography, TextField } from "@material-ui/core"; | ||
import Autocomplete from "@material-ui/lab/Autocomplete"; | ||
import { gql, useQuery } from "@apollo/client"; | ||
|
||
const QUERY = gql` | ||
query FindOrganization($keyword: String!) { | ||
organizations(keyword: $keyword, limit: 15) { | ||
id | ||
name | ||
} | ||
} | ||
`; | ||
|
||
const OrganizationPicker = ({ setOrgId }) => { | ||
const [orgName, setOrgName] = React.useState(""); | ||
const [keyword, setKeyword] = React.useState(""); | ||
const { data, loading } = useQuery(QUERY, { | ||
variables: { keyword } | ||
}); | ||
const options = data === undefined ? [] : data.organizations; | ||
return ( | ||
<div> | ||
<Typography variant={"h5"}>Currently Selected Club: </Typography> | ||
<div> | ||
{orgName === "" ? ( | ||
<Autocomplete | ||
options={options} | ||
value={null} | ||
getOptionLabel={_ => ""} | ||
renderOption={option => <span>{option.name}</span>} | ||
onChange={(ev, newvalue) => { | ||
setOrgName(newvalue.name); | ||
setOrgId(newvalue.id); | ||
}} | ||
loading={loading} | ||
filterOptions={f => f} | ||
renderInput={params => ( | ||
<TextField | ||
{...params} | ||
required={true} | ||
label="Find Organization" | ||
variant="outlined" | ||
value={keyword} | ||
onChange={ev => setKeyword(ev.target.value)} | ||
/> | ||
)} | ||
/> | ||
) : ( | ||
<Typography variant={"h5"}>{orgName}</Typography> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default OrganizationPicker; |
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
Oops, something went wrong.