2019-10-12 21:52:04 +05:30
import { nextView } from '../store' ;
import { localStorage , COMMENT _BOX , LOGOUT , STORAGE _MR _ID , STORAGE _TOKEN } from '../shared' ;
import { clearNote } from './note' ;
import { buttonClearStyles } from './utils' ;
import { addForm } from './wrapper' ;
import { changeSelectedMr , selectedMrNote } from './comment_mr_note' ;
import postComment from './comment_post' ;
import { saveComment , getSavedComment } from './comment_storage' ;
const comment = state => {
const savedComment = getSavedComment ( ) ;
return `
< div >
< textarea id = "${COMMENT_BOX}" name = "${COMMENT_BOX}" rows = "3" placeholder = "Enter your feedback or idea" class = "gitlab-input" aria - required = "true" > $ { savedComment } < / t e x t a r e a >
$ { selectedMrNote ( state ) }
< p class = "gitlab-metadata-note" > Additional metadata will be included : browser , OS , current page , user agent , and viewport dimensions . < / p >
< / d i v >
< div class = "gitlab-button-wrapper" >
< button class = "gitlab-button gitlab-button-success" style = "${buttonClearStyles}" type = "button" id = "gitlab-comment-button" > Send feedback < / b u t t o n >
< button class = "gitlab-button gitlab-button-secondary" style = "${buttonClearStyles}" type = "button" id = "${LOGOUT}" > Log out < / b u t t o n >
< / d i v >
2019-09-04 21:01:54 +05:30
` ;
2019-10-12 21:52:04 +05:30
} ;
2019-09-04 21:01:54 +05:30
2019-10-12 21:52:04 +05:30
// This function is here becaause it is called only from the comment view
// If we reach a design where we can logout from multiple views, promote this
// to it's own package
const logoutUser = state => {
localStorage . removeItem ( STORAGE _TOKEN ) ;
localStorage . removeItem ( STORAGE _MR _ID ) ;
state . token = '' ;
state . mergeRequestId = '' ;
clearNote ( ) ;
addForm ( nextView ( state , COMMENT _BOX ) ) ;
2019-09-04 21:01:54 +05:30
} ;
2019-10-12 21:52:04 +05:30
export { changeSelectedMr , comment , logoutUser , postComment , saveComment } ;