This repository has been archived by the owner on Oct 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
feat: added json validation and import error modal #25
Open
vinhvn
wants to merge
2
commits into
main
Choose a base branch
from
vinh/15-add-data-validation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import React from 'react'; | ||
import styled from 'styled-components'; | ||
import Modal from '..'; | ||
|
||
interface FileErrorModalProps { | ||
files: string[]; | ||
onClose: () => void; | ||
} | ||
|
||
const ErrorModal: React.FC<FileErrorModalProps> = ({ | ||
onClose, | ||
files | ||
}: FileErrorModalProps) => { | ||
return ( | ||
<Modal onClose={onClose}> | ||
<ErrorHeader>There was an error importing some files.</ErrorHeader> | ||
<ErrorText>Files that could not be imported:</ErrorText> | ||
Comment on lines
+16
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should add a |
||
<ErrorList> | ||
{files.map((file, i) => ( | ||
<ErrorItem key={`${file}-${i}`}>{file}</ErrorItem> | ||
))} | ||
</ErrorList> | ||
Comment on lines
+18
to
+22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Likewise for the error content, the list could be specified via a prop. |
||
</Modal> | ||
); | ||
}; | ||
|
||
const ErrorHeader = styled.h2` | ||
font-size: 1rem; | ||
line-height: 1.5rem; | ||
margin: 0px; | ||
margin-bottom: 1em; | ||
`; | ||
|
||
const ErrorText = styled.p` | ||
font-size: 0.875rem; | ||
line-height: 1.25rem; | ||
margin: 0px; | ||
`; | ||
|
||
const ErrorList = styled.ul` | ||
padding-left: 1em; | ||
margin: 0px; | ||
`; | ||
|
||
const ErrorItem = styled.li` | ||
font-size: 0.875rem; | ||
line-height: 1.25rem; | ||
margin: 0px; | ||
`; | ||
|
||
export default ErrorModal; |
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,3 @@ | ||
import FileErrorModal from './FileErrorModal'; | ||
|
||
export default FileErrorModal; |
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,85 @@ | ||
import React from 'react'; | ||
import styled from 'styled-components'; | ||
|
||
interface ModalProps { | ||
onClose: () => void; | ||
children?: React.ReactNode; | ||
} | ||
|
||
const Modal: React.FC<ModalProps> = ({ onClose, children }: ModalProps) => { | ||
return ( | ||
<ModalContainer> | ||
<ModalBackground onClick={() => onClose()} /> | ||
<ModalContent> | ||
<ModalHeader> | ||
<ModalCloseButton onClick={() => onClose()}> | ||
<svg | ||
xmlns='http://www.w3.org/2000/svg' | ||
style={{ width: '1.25rem' }} | ||
fill='none' | ||
viewBox='0 0 24 24' | ||
stroke='currentColor' | ||
> | ||
<path | ||
strokeLinecap='round' | ||
strokeLinejoin='round' | ||
strokeWidth={2} | ||
d='M6 18L18 6M6 6l12 12' | ||
/> | ||
</svg> | ||
</ModalCloseButton> | ||
</ModalHeader> | ||
{children} | ||
</ModalContent> | ||
</ModalContainer> | ||
); | ||
}; | ||
|
||
const ModalContainer = styled.div` | ||
position: fixed; | ||
top: 0px; | ||
right: 0px; | ||
bottom: 0px; | ||
left: 0px; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
z-index: 10; | ||
`; | ||
|
||
const ModalBackground = styled.div` | ||
position: absolute; | ||
top: 0px; | ||
right: 0px; | ||
bottom: 0px; | ||
left: 0px; | ||
background-color: #000; | ||
opacity: 0.8; | ||
`; | ||
|
||
const ModalContent = styled.div` | ||
position: relative; | ||
display: flex; | ||
flex-direction: column; | ||
background-color: #fff; | ||
opacity: 1; | ||
padding: 2em; | ||
padding-bottom: 3em; | ||
border-radius: 0.25rem; | ||
`; | ||
|
||
const ModalHeader = styled.div` | ||
display: flex; | ||
justify-content: flex-end; | ||
width: 100%; | ||
`; | ||
|
||
const ModalCloseButton = styled.button` | ||
margin: 0px; | ||
padding: 0px; | ||
cursor: pointer; | ||
background: none; | ||
border: none; | ||
`; | ||
|
||
export default 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import Modal from './Modal'; | ||
|
||
export default Modal; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.