mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-04-24 23:19:39 -05:00
admin panel end voting
This commit is contained in:
parent
17cb91cd87
commit
8db2785c2f
|
|
@ -53,7 +53,10 @@ const AdminPanel = () => {
|
|||
handleError={handleError}
|
||||
/>
|
||||
<VotingManager
|
||||
handleSuccess={message => handleSuccess(message)}
|
||||
handleSuccess={(message, link) => {
|
||||
handleSuccess(message)
|
||||
if (link) setLink(link)
|
||||
}}
|
||||
handleError={handleError}
|
||||
/>
|
||||
</>
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
) : (
|
||||
<>
|
||||
|
|
|
|||
7
frontend-react/src/graphql/mutations/endVoting.js
Normal file
7
frontend-react/src/graphql/mutations/endVoting.js
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import { gql } from "apollo-boost"
|
||||
|
||||
export const endVoting = gql`
|
||||
mutation {
|
||||
endVoting
|
||||
}
|
||||
`
|
||||
Loading…
Reference in New Issue
Block a user