admin panel end voting

This commit is contained in:
Sendou 2020-01-06 02:42:57 +02:00
parent 17cb91cd87
commit 8db2785c2f
3 changed files with 31 additions and 1 deletions

View File

@ -53,7 +53,10 @@ const AdminPanel = () => {
handleError={handleError}
/>
<VotingManager
handleSuccess={message => handleSuccess(message)}
handleSuccess={(message, link) => {
handleSuccess(message)
if (link) setLink(link)
}}
handleError={handleError}
/>
</>

View File

@ -8,6 +8,7 @@ import { useQuery, useMutation } from "@apollo/react-hooks"
import { plusInfo } from "../../graphql/queries/plusInfo"
import { startVoting } from "../../graphql/mutations/startVoting"
import { Message, Button } from "semantic-ui-react"
import { endVoting } from "../../graphql/mutations/endVoting"
const VotingManager = ({ handleSuccess, handleError }) => {
const [endDate, setEndDate] = useState(new Date())
@ -24,6 +25,16 @@ const VotingManager = ({ handleSuccess, handleError }) => {
],
})
const [endVotingMutation] = useMutation(endVoting, {
onError: handleError,
onCompleted: () => handleSuccess("Voting has concluded!", "/plus/history"),
refetchQueries: [
{
query: plusInfo,
},
],
})
if (loading) return <Loading />
if (error) return <Error errorMessage={error.message} />
@ -36,6 +47,15 @@ const VotingManager = ({ handleSuccess, handleError }) => {
<b>
{new Date(parseInt(data.plusInfo.voting_ends)).toLocaleString()}
</b>
<div style={{ marginTop: "1em" }}>
{!confirmed ? (
<Button onClick={() => setConfirmed(true)}>End voting</Button>
) : (
<Button onClick={async () => await endVotingMutation()}>
End voting for real?
</Button>
)}
</div>
</Message>
) : (
<>

View File

@ -0,0 +1,7 @@
import { gql } from "apollo-boost"
export const endVoting = gql`
mutation {
endVoting
}
`