-
Notifications
You must be signed in to change notification settings - Fork 7
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
Showing
9 changed files
with
139 additions
and
211 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,19 @@ | ||
.header { | ||
font-size: 20px; | ||
font-weight: 500; | ||
margin-top: 0; | ||
margin-bottom: var(--spacers-dp16); | ||
} | ||
|
||
.warning { | ||
font-size: 16px; | ||
color: var(--colors-grey700); | ||
} | ||
|
||
.uploadBtn { | ||
margin-top: var(--spacers-dp16); | ||
} | ||
|
||
.hiddenForm { | ||
display: none; | ||
} |
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,5 +1,87 @@ | ||
import React from 'react' | ||
import { useAlert, useConfig } from '@dhis2/app-runtime' | ||
import i18n from '@dhis2/d2-i18n' | ||
import { Button } from '@dhis2/ui' | ||
import React, { useState, useRef } from 'react' | ||
import styles from './ManualInstall.module.css' | ||
|
||
const ManualInstall = () => null | ||
const uploadApp = (baseUrl, file) => { | ||
const data = new FormData() | ||
data.append('file', file) | ||
return fetch(`${baseUrl}/api/apps`, { | ||
method: 'post', | ||
body: data, | ||
credentials: 'include', | ||
}).then(res => { | ||
if (status >= 300) { | ||
throw new Error(res.statusText) | ||
} | ||
}) | ||
} | ||
|
||
const UploadButton = () => { | ||
const { baseUrl } = useConfig() | ||
const [isUploading, setIsUploading] = useState(false) | ||
const successAlert = useAlert(i18n.t('App installed successfully'), { | ||
success: true, | ||
}) | ||
const errorAlert = useAlert( | ||
({ error }) => | ||
i18n.t('Failed to install app: {{errorMessage}}', { | ||
errorMessage: error.message, | ||
nsSeparator: '|', | ||
}), | ||
{ critical: true } | ||
) | ||
const formEl = useRef(null) | ||
const inputEl = useRef(null) | ||
const handleClick = () => { | ||
inputEl.current.click() | ||
} | ||
const handleUpload = async event => { | ||
setIsUploading(true) | ||
try { | ||
await uploadApp(baseUrl, event.target.files[0]) | ||
formEl.current.reset() | ||
successAlert.show() | ||
} catch (error) { | ||
errorAlert.show({ error }) | ||
} | ||
setIsUploading(false) | ||
} | ||
|
||
return ( | ||
<> | ||
<form className={styles.hiddenForm} ref={formEl}> | ||
<input | ||
type="file" | ||
accept="application/zip" | ||
ref={inputEl} | ||
onChange={handleUpload} | ||
/> | ||
</form> | ||
<Button | ||
className={styles.uploadBtn} | ||
onClick={handleClick} | ||
disabled={isUploading} | ||
> | ||
{isUploading | ||
? i18n.t('Uploading...') | ||
: i18n.t('Upload an app to install')} | ||
</Button> | ||
</> | ||
) | ||
} | ||
|
||
const ManualInstall = () => ( | ||
<> | ||
<h1 className={styles.header}>{i18n.t('Manually install an app')}</h1> | ||
<p className={styles.warning}> | ||
{i18n.t( | ||
'Installed apps have access to your DHIS2 data and metadata. Make sure you trust an app before installing it.' | ||
)} | ||
</p> | ||
<UploadButton /> | ||
</> | ||
) | ||
|
||
export default ManualInstall |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.