-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update video states #159
Update video states #159
Conversation
src/pages/DummyHomePage/index.js
Outdated
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.
Can you please merge the latest main? I think we treat this component as the actual home page now
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.
You are right. Tank you. Removed all buttons examples from that page.
Added to comment above "To use VideoActionButton you need to add <VideoActionButton key={key} videoData={someVideoData} action={actionName}/>
- options for possible actionNames are in constant ACTION_NAME in src/utils/constants.js
"
src/utils/constants.js
Outdated
}; | ||
|
||
export const VIDEO_STATE = { | ||
DRAFT: 'draft', //[USER: prevState === null (just uploaded)], |
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.
The comment here is not entirely correct, right? It could be that the video was moved to draft
src/utils/constants.js
Outdated
{//DELETE | ||
action: ACTION_NAME.DELETE, | ||
currentState: VIDEO_STATE.DRAFT, | ||
nextSate: null,//do we keep it in DB? |
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.
I think delete is a delete, we should remove the record from the database. Let's leave this for now and implement the delete functionality 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.
Yes, I remember that we discussed this and agreed to not to keep them in DB, I just forgot to delete the comment.
src/utils/constants.js
Outdated
nextSate: VIDEO_STATE.DRAFT | ||
}, | ||
{//PUT | ||
action: ACTION_NAME.MOVE_TO_PENDING, |
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.
nit: Should we rename this action to SEND_FOR_REVIEW? What do you think? We might then rename the pending state to IN_REVIEW as well.
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.
Super!. SEND_FOR_REVIEW is much better.
src/utils/validateChangeState.js
Outdated
@@ -0,0 +1,40 @@ | |||
import { VIDEO_DATA_KEYS, USER_ROLE, VIDEO_STATE, ACTION_NAME } from './constants'; | |||
|
|||
export const validateChangeState = ({videoData, action, userRole}) => { |
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.
I think we can simplify this function by reusing the logic you've implemented in constants.js.
Imagine that we have an object that looks like the following:
videoStates =
{
"user": {
"MOVE_TO_PENDING": {
"validate": (currentState) => currentState == DRAFT,
"nextState": "PENDING"
},
"MOVE_TO_DRAFT": {....},
// other actions
},
"admin": {
"APPROVE": {
"validate": (currentState) => currentState == PENDING
"nextState": "APPROVED"
},
// other actions
}
Then we can use this object in the validateChangeState function as the following:
val state = videoStates[user.role][action]
val isValid = state["validate"](videoData[VIDE_DATA_KEYS.STATE])
if (isValid) state["nextState"]
I think this will allow us to have the logic defined in the videoStates object and the validateChangeState function will be simple without lots of nested if conditions. Let me know what you think.
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.
@sherif98 it sounds great. It really should be much simpler and more readable. I'll do it now. Thank you so much for your review 🫶
src/utils/validateChangeState.js
Outdated
if (userRole === USER_ROLE.USER && currentVideoState === VIDEO_STATE.PENDING) { | ||
nextState = VIDEO_STATE.APPROVED; |
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.
Is this correct? Can a user approve a video?
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.
Of course it is not correct 😱. The right code should be
if (action === ACTION_NAME.APPROVE) {
if (userRole === USER_ROLE.ADMIN && (currentVideoState === VIDEO_STATE.IN_REVIEW)) {
nextState = VIDEO_STATE.APPROVED;
}
Thank you!
@sherif98 thank you very much for your review 🫶 I've updated my code according to your comments. Hope very much you will have time to look through it once again with my updates. |
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.
LGTM! Looks great now Iryna!
@@ -31,3 +31,18 @@ export const getAllVideoByUserID = (UserID) => { | |||
console.log(error); | |||
}); | |||
}; | |||
|
|||
export const apiUpdateVideo = (updatedVideo, handleSnackbar) => { |
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.
nit: rename handleSnackbar to a more generic name, for example handleStatus or reportStatus. The reason is that in API level (in videos.js) it doesn't need to know that you're using a snackbar or an error message or whatever to display something to user, it should be agnostic on the API level
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.
Please merge the latest main and update the PR. I don't think this file is newly added here, it was added in the SortBy PR
if(isValid) { | ||
return VIDEO_STATE_UPDATE_ACTIONS[userRole][action].nextSate; | ||
} else { | ||
return false; |
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.
In the if branch we return a string (the state) while here we return a boolean, can we unify the return type of the function? Maybe make it return undefined here or so?
What do you think?
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.
well-written and structured code makes it easily readable, good use of the use context from react for accessing of the user role
//navigate to somewhere | ||
}); | ||
} else if(action === ACTION_NAME.DELETE){ | ||
console.log('add delete confirmation and axios request') |
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.
It seems like you've handled everything well. Great job! Perhaps, in the future, we could consider incorporating a pop-up message or a text that says, "Are you sure you want to delete this video?" This will provide a double confirmation with a Yes or No option
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.
👏 Great job! You've done an excellent job with this pull request! 👏
Ticket https://github.com/JoeWeate/thebigmouth/issues/139
apiUpdateVideo
axios request functionVideoActionButton
component with all buttons view and logicSnackbar
component and added for video state updatesTo use VideoActionButton you need to add
<VideoActionButton key={key} videoData={someVideoData} action={actionName}/>
- options for possible actionNames are in constantACTION_NAME in src/utils/constants.js
All types of buttons temporary placed at the bottom of our DummyHomePage. Pay attention that you will see all the buttons - for admin and for user as userRole is fake(userRole === USER_ROLE.USER, userRole !== USER_ROLE.ADMIN) but their working logic as for real user
