-
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
1 parent
d30f5f9
commit 24961ba
Showing
7 changed files
with
197 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import React, { useCallback } from 'react'; | ||
import styled from 'styled-components'; | ||
|
||
import { UploadIcon, SuccessIcon } from '..'; | ||
|
||
const StyledDiv = styled('div')` | ||
border: 1px dotted #d9d9d9; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
height: 120px; | ||
& label { | ||
cursor: pointer; | ||
} | ||
`; | ||
|
||
const StyledInput = styled('input')` | ||
visibility: hidden; | ||
width: 0px; | ||
height: 0px; | ||
`; | ||
|
||
const UploadFileInput = ({ file, onChange }) => { | ||
const onFileInputChange = useCallback(e => { | ||
if (e.target.value && e.target.value !== '') { | ||
const file = e.target.files[0]; | ||
onChange(file); | ||
} | ||
}, []); | ||
|
||
return ( | ||
<StyledDiv> | ||
<label htmlFor="file"> | ||
{!file && <UploadIcon width="20" height="20" />} | ||
{file && <SuccessIcon width="20" height="20" />} | ||
</label> | ||
<StyledInput type="file" id="file" onChange={onFileInputChange} /> | ||
</StyledDiv> | ||
); | ||
}; | ||
|
||
export { UploadFileInput }; |
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,121 @@ | ||
/* eslint-disable */ | ||
import React, { useEffect, useState } from 'react'; | ||
import { FormattedMessage, useIntl } from 'react-intl'; | ||
import { useSelector, useDispatch } from 'react-redux'; | ||
|
||
import { | ||
Modal, | ||
Body, | ||
InputSizeEnum, | ||
StandardInput, | ||
InputVariantEnum, | ||
modalTypeEnum, | ||
InputContainer, | ||
StyledFieldContainer, | ||
StyledLabelContainer, | ||
ModalFormContainerStyle, | ||
UploadFileInput, | ||
} from '..'; | ||
import { isValidFileName } from '../../utils/stringUtils'; | ||
|
||
const FileUploadModal = ({ onClose }) => { | ||
const intl = useIntl(); | ||
const dispatch = useDispatch(); | ||
const { notification } = useSelector(state => state.app); | ||
const [formData, setFormData] = useState({ | ||
fileName: '', | ||
file: null, | ||
}); | ||
|
||
const fileNameIsValid = isValidFileName(formData.fileName); | ||
const fileIsValid = formData?.file != null; | ||
|
||
const onSubmit = async () => { | ||
if (fileNameIsValid && fileIsValid) { | ||
// TO DO IMPLEMENT STORE ACTION | ||
// dispatch(editExistingOrg(formData)); | ||
} | ||
}; | ||
|
||
const orgWasSuccessfullyCreated = | ||
notification && notification.id === 'file-uploaded'; | ||
useEffect(() => { | ||
if (orgWasSuccessfullyCreated) { | ||
onClose(); | ||
} | ||
}, [notification]); | ||
|
||
return ( | ||
<> | ||
<Modal | ||
onOk={onSubmit} | ||
onClose={onClose} | ||
modalType={modalTypeEnum.basic} | ||
title={intl.formatMessage({ | ||
id: 'file-upload', | ||
})} | ||
label={intl.formatMessage({ | ||
id: 'upload', | ||
})} | ||
body={ | ||
<ModalFormContainerStyle> | ||
<StyledFieldContainer> | ||
<StyledLabelContainer> | ||
<Body> | ||
*<FormattedMessage id="filename" /> | ||
</Body> | ||
</StyledLabelContainer> | ||
<InputContainer> | ||
<StandardInput | ||
size={InputSizeEnum.large} | ||
variant={InputVariantEnum.default} | ||
value={formData.fileName} | ||
onChange={value => | ||
setFormData(prevState => ({ | ||
...prevState, | ||
fileName: value, | ||
})) | ||
} | ||
/> | ||
</InputContainer> | ||
{!fileNameIsValid && ( | ||
<Body size="Small" color="red"> | ||
{intl.formatMessage({ | ||
id: 'add-valid-filename', | ||
})} | ||
</Body> | ||
)} | ||
</StyledFieldContainer> | ||
<StyledFieldContainer> | ||
<StyledLabelContainer> | ||
<Body> | ||
*<FormattedMessage id="file" /> | ||
</Body> | ||
</StyledLabelContainer> | ||
<InputContainer> | ||
<UploadFileInput | ||
onChange={file => | ||
setFormData(prevState => ({ | ||
...prevState, | ||
file: file, | ||
})) | ||
} | ||
file={formData.file} | ||
/> | ||
</InputContainer> | ||
{!fileNameIsValid && ( | ||
<Body size="Small" color="red"> | ||
{intl.formatMessage({ | ||
id: 'add-valid-file', | ||
})} | ||
</Body> | ||
)} | ||
</StyledFieldContainer> | ||
</ModalFormContainerStyle> | ||
} | ||
/> | ||
</> | ||
); | ||
}; | ||
|
||
export { FileUploadModal }; |
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