-
Notifications
You must be signed in to change notification settings - Fork 82
Switch Profile Between Learner & Instructor #2312
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
Conversation
| { | ||
| onSuccess: (res: AjaxResponse) => { | ||
| window.TutorCore.toast.success(res?.message); | ||
| setTimeout(() => { |
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.
Why this delay? In production ajax calls usually takes longer times.
| } | ||
|
|
||
| $switch_mode = ''; | ||
| $current_mode = Input::post( 'current_mode' ); |
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 variable name is confusing because the user already has a current mode.
Use switch_mode to clearly indicate the target mode.
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.
$switch_mode = Input('switch_mode' );
$profile_mode = self::VIEW_AS_STUDENT === $switch_mode ? self::VIEW_AS_STUDENT : self::VIEW_AS_INSTRUCTOR;
update_user_meta( $user_id, self::VIEW_MODE_USER_META, $profile_mode );| $is_instructor = self::is_instructor( $user_id, true ); | ||
| $is_admin = self::is_admin( $user_id ); | ||
|
|
||
| $default_mode = $is_instructor || $is_admin ? self::VIEW_AS_INSTRUCTOR : self::VIEW_AS_STUDENT; |
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.
To check multiple condition for ternary use ( )
$default_mode = ( $is_instructor || $is_admin ) ? self::VIEW_AS_INSTRUCTOR : self::VIEW_AS_STUDENT;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.
Instead of defining a new interface, use TutorMutationResponse
To me, it seems sensible to keep things together for a single mutation. Co-authored-by: Fahim Faisal <42368238+b-l-i-n-d@users.noreply.github.com>
…o profile-switch
switch profile to learner/instructorAjaxResponseadded