-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bd2307f
commit bd0fc49
Showing
15 changed files
with
248 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,7 +87,7 @@ | |
-moz-appearance: textfield; | ||
} | ||
|
||
.warning { | ||
.message { | ||
margin-top: 1rem; | ||
margin-bottom: 3.3rem; | ||
} | ||
|
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,11 +1,15 @@ | ||
Cypress.Commands.add( | ||
"mockResponse", | ||
(routeMatcher, mockFn, { headers = {}, statusCode = 200 } = {}) => { | ||
( | ||
routeMatcher, | ||
mockFn, | ||
{ headers = {}, statusCode = 200, ...replyParams } = {} | ||
) => { | ||
if (!routeMatcher) return; | ||
return cy.intercept(routeMatcher, (req) => { | ||
const params = req.body || {}; | ||
const body = mockFn(params); | ||
req.reply({ body, headers, statusCode }); | ||
req.reply({ body, headers, statusCode, ...replyParams }); | ||
}); | ||
} | ||
); |
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
30 changes: 30 additions & 0 deletions
30
plugins-structure/packages/ticketvote/src/ui/TicketSearch/ModalTicketSearch.js
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,30 @@ | ||
import React from "react"; | ||
import PropTypes from "prop-types"; | ||
import { Modal } from "pi-ui"; | ||
import { TicketSearch } from "./TicketSearch"; | ||
|
||
export function ModalTicketSearch({ | ||
placeholder, | ||
onClose, | ||
title, | ||
show, | ||
token, | ||
}) { | ||
return ( | ||
<Modal show={show} onClose={onClose} title={title}> | ||
<TicketSearch placeholder={placeholder} token={token} /> | ||
</Modal> | ||
); | ||
} | ||
|
||
ModalTicketSearch.propTypes = { | ||
token: PropTypes.string.isRequired, | ||
placeholder: PropTypes.string, | ||
onClose: PropTypes.func, | ||
title: PropTypes.node, | ||
show: PropTypes.bool, | ||
}; | ||
|
||
ModalTicketSearch.defaultProps = { | ||
title: "Search Ticket Vote", | ||
}; |
74 changes: 74 additions & 0 deletions
74
plugins-structure/packages/ticketvote/src/ui/TicketSearch/TicketSearch.js
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,74 @@ | ||
import React, { useEffect, useState } from "react"; | ||
import PropTypes from "prop-types"; | ||
import { useDispatch, useSelector } from "react-redux"; | ||
import { Table } from "pi-ui"; | ||
import { RecordForm } from "@politeiagui/common-ui"; | ||
import styles from "./styles.module.css"; | ||
import { ticketvoteResults } from "../../ticketvote/results"; | ||
|
||
export function TicketSearch({ placeholder, token }) { | ||
const dispatch = useDispatch(); | ||
|
||
const [resultsFound, setResultsFound] = useState(); | ||
|
||
const results = useSelector((state) => | ||
ticketvoteResults.selectByToken(state, token) | ||
); | ||
|
||
const resultsStatus = useSelector(ticketvoteResults.selectStatus); | ||
const error = useSelector(ticketvoteResults.selectError); | ||
|
||
function handleSearchTicket({ ticketToken }) { | ||
const tickets = results | ||
.filter((r) => r.ticket === ticketToken) | ||
.map((ticket) => ({ | ||
Ticket: ticket.ticket, | ||
Option: ticket.votebit === "2" ? "Yes" : "No", | ||
})); | ||
setResultsFound(tickets); | ||
} | ||
|
||
useEffect(() => { | ||
dispatch(ticketvoteResults.fetch({ token })); | ||
}, [dispatch, token]); | ||
|
||
const isLoading = resultsStatus === "loading"; | ||
|
||
return ( | ||
<div> | ||
{isLoading && ( | ||
<div | ||
className={styles.loading} | ||
data-testid="ticketvote-modal-ticket-search-loading" | ||
/> | ||
)} | ||
<RecordForm onSubmit={handleSearchTicket} className={styles.searchForm}> | ||
{({ TextInput, ErrorMessage }) => ( | ||
<> | ||
{error && <ErrorMessage error={error} />} | ||
<TextInput | ||
name="ticketToken" | ||
placeholder={isLoading ? "Loading..." : placeholder} | ||
disabled={isLoading || error} | ||
data-testid="ticketvote-modal-ticket-search-input" | ||
/> | ||
</> | ||
)} | ||
</RecordForm> | ||
{resultsFound && ( | ||
<div data-testid="ticketvote-modal-ticket-search-table"> | ||
<Table headers={["Ticket", "Option"]} data={resultsFound} /> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
} | ||
|
||
TicketSearch.propTypes = { | ||
token: PropTypes.string.isRequired, | ||
placeholder: PropTypes.string, | ||
}; | ||
|
||
TicketSearch.defaultProps = { | ||
placeholder: "Search by ticket token", | ||
}; |
2 changes: 2 additions & 0 deletions
2
plugins-structure/packages/ticketvote/src/ui/TicketSearch/index.js
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,2 @@ | ||
export * from "./ModalTicketSearch"; | ||
export * from "./TicketSearch"; |
33 changes: 33 additions & 0 deletions
33
plugins-structure/packages/ticketvote/src/ui/TicketSearch/styles.module.css
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,33 @@ | ||
.searchForm { | ||
padding: 0 !important; | ||
} | ||
|
||
.loading { | ||
width: 50%; | ||
height: 0.3rem; | ||
background-color: var(--color-primary); | ||
top: 0; | ||
left: 0; | ||
position: fixed; | ||
animation: slide 2s linear infinite; | ||
overflow: hidden; | ||
} | ||
|
||
@keyframes slide { | ||
0% { | ||
left: 0; | ||
width: 0%; | ||
} | ||
25% { | ||
left: 0%; | ||
width: 33%; | ||
} | ||
75% { | ||
left: 67%; | ||
width: 33%; | ||
} | ||
100% { | ||
left: 100%; | ||
width: 0%; | ||
} | ||
} |
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.