Created
November 10, 2016 15:06
-
-
Save boo1ean/6e3f459985c447363af88737b5a56858 to your computer and use it in GitHub Desktop.
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
const EditPage = (props) => { | |
switch (true) { | |
case editPlatformNoData(props): return fetchPlatform(props) | |
case editPlatformHasData(props): return <EditForm onSubmit={props.updatePlatform} initialValues={props.data} /> | |
case newPlatform(props): return <EditForm onSubmit={props.createPlatform} /> | |
case error(props): return <h2>нельзя такое редактировать</h2> | |
default: throw new Error('Undefined state') | |
} | |
function newPlatform (props) { | |
return !props.params.id | |
} | |
function editPlatformNoData (props) { | |
return !error(props) && props.params.id && !props.data | |
} | |
function editPlatformHasData (props) { | |
return !!props.params.id && props.data | |
} | |
function fetchPlatform () { | |
props.fetchPlatform({ _id: props.params.id }) | |
return <h2>ожидайте</h2> | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment