-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dues estimator to reduce currencylayer usage
- Loading branch information
1 parent
221c44f
commit 0d4b87b
Showing
5 changed files
with
72 additions
and
60 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
48 changes: 48 additions & 0 deletions
48
app/webpacker/components/CompetitionForm/FormSections/DuesEstimate.jsx
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,48 @@ | ||
import React, { useMemo } from 'react'; | ||
import { Input, Modal } from 'semantic-ui-react'; | ||
import useInputState from '../../../lib/hooks/useInputState'; | ||
import { calculateDuesUrl } from '../../../lib/requests/routes.js.erb'; | ||
import { currenciesData } from '../../../lib/wca-data.js.erb'; | ||
import useLoadedData from '../../../lib/hooks/useLoadedData'; | ||
import Loading from '../../Requests/Loading'; | ||
import Errored from '../../Requests/Errored'; | ||
|
||
export default function DuesEstimate({ | ||
close, countryId, currencyCode, baseEntryFee, competitorLimit, | ||
}) { | ||
const [competitorCount, setCompetitorCount] = useInputState(competitorLimit || 0); | ||
const currencyInfo = useMemo( | ||
() => (currenciesData.byIso[currencyCode] || currenciesData.byIso.USD), | ||
[currencyCode], | ||
); | ||
|
||
const { | ||
data, loading, error, | ||
} = useLoadedData(calculateDuesUrl(countryId, currencyCode, baseEntryFee)); | ||
|
||
const { dues_value: duesValue } = data || {}; | ||
|
||
if (loading) return <Loading />; | ||
if (error) return <Errored error="Dues fetching failed..." />; | ||
|
||
return ( | ||
<Modal | ||
open | ||
onClose={close} | ||
closeIcon | ||
> | ||
<Modal.Header>Dues Estimate</Modal.Header> | ||
<Modal.Content> | ||
<Input | ||
label="Competitor count" | ||
type="number" | ||
value={competitorCount} | ||
onChange={setCompetitorCount} | ||
/> | ||
<p> | ||
{`Dues for ${competitorCount} competitors (approximately): ${currencyInfo?.symbol || ''}${(duesValue * competitorCount).toFixed(2)}`} | ||
</p> | ||
</Modal.Content> | ||
</Modal> | ||
); | ||
} |
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