-
Notifications
You must be signed in to change notification settings - Fork 15
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 #150 from leinelissen/providers-ui
Providers ui
- Loading branch information
Showing
16 changed files
with
394 additions
and
70 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
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,94 @@ | ||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; | ||
import { faCheck, faClock, faPlus, faQuestion, faSync } from 'app/assets/fa-light'; | ||
import Button from 'app/components/Button'; | ||
import RightSideOverlay, { Section } from 'app/components/RightSideOverlay'; | ||
import { H2 } from 'app/components/Typography'; | ||
import Providers from 'app/utilities/Providers'; | ||
import { formatDistanceToNow } from 'date-fns'; | ||
import { DataRequestStatus } from 'main/providers/types'; | ||
import React, { useCallback } from 'react'; | ||
|
||
interface Props { | ||
selectedProvider: string; | ||
status?: DataRequestStatus; | ||
} | ||
|
||
function ProviderOverlay({ selectedProvider, status }: Props): JSX.Element { | ||
const handleNewRequest = useCallback(() => { | ||
Providers.dispatchDataRequest(selectedProvider); | ||
}, [selectedProvider]); | ||
|
||
return ( | ||
<RightSideOverlay> | ||
{selectedProvider && ( | ||
<> | ||
<Section> | ||
<H2> | ||
<FontAwesomeIcon | ||
icon={Providers.getIcon(selectedProvider)} | ||
style={{ marginRight: 8 }} | ||
/> | ||
{selectedProvider} | ||
</H2> | ||
</Section> | ||
<Section> | ||
<span> | ||
<FontAwesomeIcon | ||
icon={faQuestion} | ||
style={{ marginRight: 8 }} | ||
fixedWidth | ||
/> | ||
Data requested: <i>{status?.dispatched ? formatDistanceToNow(status.dispatched) + ' ago' : 'never'}</i> | ||
<br /> | ||
<FontAwesomeIcon | ||
icon={faClock} | ||
style={{ marginRight: 8 }} | ||
fixedWidth | ||
/> | ||
Last check: <i>{status?.lastCheck ? formatDistanceToNow(status.lastCheck) + ' ago' : 'never'}</i> | ||
{status?.completed && | ||
<> | ||
<br /> | ||
<FontAwesomeIcon | ||
icon={faCheck} | ||
style={{ marginRight: 8 }} | ||
fixedWidth | ||
/> | ||
Completed: <i>{formatDistanceToNow(status?.completed)} ago</i> | ||
</> | ||
} | ||
</span> | ||
</Section> | ||
{status?.dispatched ? | ||
<Section> | ||
<p>The data request you issued has not been completed yet. We'll let you know as soon as it's completed.</p> | ||
<Button | ||
fullWidth | ||
icon={faCheck} | ||
onClick={handleNewRequest} | ||
disabled | ||
> | ||
Complete Data Request | ||
</Button> | ||
</Section> | ||
: | ||
<Section> | ||
<p>If you would like to retrieve your data, use the button below to start a new data request.</p> | ||
<p><i>Note: you may be asked to confirm your password</i></p> | ||
<Button | ||
fullWidth | ||
icon={faPlus} | ||
onClick={handleNewRequest} | ||
disabled={!!status?.dispatched} | ||
> | ||
Start Data Request | ||
</Button> | ||
</Section> | ||
} | ||
</> | ||
)} | ||
</RightSideOverlay> | ||
); | ||
} | ||
|
||
export default ProviderOverlay; |
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,17 @@ | ||
import { formatDistanceToNow } from 'date-fns'; | ||
import { DataRequestStatus } from 'main/providers/types'; | ||
|
||
/** | ||
* A helper to convert a particular DataRequestStatus to a human-readable string | ||
*/ | ||
export default function getDescription(status?: DataRequestStatus): string { | ||
if (status?.completed) { | ||
return `Received data ${formatDistanceToNow(status.completed)} ago`; | ||
} | ||
|
||
if (status?.dispatched) { | ||
return `Requested data ${formatDistanceToNow(status.dispatched)} ago`; | ||
} | ||
|
||
return 'No data requested yet'; | ||
} |
Oops, something went wrong.