From b291515fa41474b8df9dc3679bf739c886fe0ebe Mon Sep 17 00:00:00 2001 From: olav Date: Wed, 9 Feb 2022 14:06:20 +0100 Subject: [PATCH] refactor: remove unused feedback state (#682) * refactor: remove unused feedback state * refactor: use PNPS feedback display logic --- frontend/src/component/App.tsx | 4 +--- .../component/common/Feedback/Feedback.tsx | 19 ++++++++----------- frontend/src/component/common/util.js | 13 +++++++------ frontend/src/store/feedback/actions.js | 8 -------- frontend/src/store/feedback/index.js | 15 --------------- frontend/src/store/index.js | 2 -- 6 files changed, 16 insertions(+), 45 deletions(-) delete mode 100644 frontend/src/store/feedback/actions.js delete mode 100644 frontend/src/store/feedback/index.js diff --git a/frontend/src/component/App.tsx b/frontend/src/component/App.tsx index e74f048560..e1a1fcef85 100644 --- a/frontend/src/component/App.tsx +++ b/frontend/src/component/App.tsx @@ -23,7 +23,6 @@ import ToastRenderer from './common/ToastRenderer/ToastRenderer'; interface IAppProps extends RouteComponentProps { user: IAuthStatus; fetchUiBootstrap: any; - feedback: any; } const App = ({ location, user, fetchUiBootstrap }: IAppProps) => { // because we need the userId when the component load. @@ -135,7 +134,6 @@ const App = ({ location, user, fetchUiBootstrap }: IAppProps) => { @@ -147,10 +145,10 @@ const App = ({ location, user, fetchUiBootstrap }: IAppProps) => { ); }; + // Set state to any for now, to avoid typing up entire state object while converting to tsx. const mapStateToProps = (state: any) => ({ user: state.user.toJS(), - feedback: state.feedback, }); export default connect(mapStateToProps)(App); diff --git a/frontend/src/component/common/Feedback/Feedback.tsx b/frontend/src/component/common/Feedback/Feedback.tsx index 6d2b9d7c48..c926b3c849 100644 --- a/frontend/src/component/common/Feedback/Feedback.tsx +++ b/frontend/src/component/common/Feedback/Feedback.tsx @@ -9,24 +9,21 @@ import { useStyles } from './Feedback.styles'; import AnimateOnMount from '../AnimateOnMount/AnimateOnMount'; import ConditionallyRender from '../ConditionallyRender'; import { formatApiPath } from '../../../utils/format-path'; -import { Action, Dispatch } from 'redux'; import UIContext from '../../../contexts/UIContext'; import useUser from '../../../hooks/api/getters/useUser/useUser'; +import { PNPS_FEEDBACK_ID, showPnpsFeedback } from '../util'; interface IFeedbackProps { - show?: boolean; - hideFeedback: () => Dispatch; - fetchUser: () => void; - feedbackId: string; openUrl: string; } -const Feedback = ({ feedbackId, openUrl }: IFeedbackProps) => { +const Feedback = ({ openUrl }: IFeedbackProps) => { const { showFeedback, setShowFeedback } = useContext(UIContext); const { refetch, feedback } = useUser(); const [answeredNotNow, setAnsweredNotNow] = useState(false); const styles = useStyles(); const commonStyles = useCommonStyles(); + const feedbackId = PNPS_FEEDBACK_ID; const onConfirm = async () => { const url = formatApiPath('api/admin/feedback'); @@ -41,7 +38,8 @@ const Feedback = ({ feedbackId, openUrl }: IFeedbackProps) => { body: JSON.stringify({ feedbackId }), }); await refetch(); - } catch { + } catch (err) { + console.warn(err); setShowFeedback(false); } @@ -68,7 +66,8 @@ const Feedback = ({ feedbackId, openUrl }: IFeedbackProps) => { body: JSON.stringify({ feedbackId, neverShow: true }), }); await refetch(); - } catch { + } catch (err) { + console.warn(err); setShowFeedback(false); } @@ -77,9 +76,7 @@ const Feedback = ({ feedbackId, openUrl }: IFeedbackProps) => { }, 100); }; - const pnps = feedback.find(feedback => feedback.feedbackId === feedbackId); - - if (pnps?.given || pnps?.neverShow) { + if (!showPnpsFeedback(feedback)) { return null; } diff --git a/frontend/src/component/common/util.js b/frontend/src/component/common/util.js index 4334e09292..cf86b94912 100644 --- a/frontend/src/component/common/util.js +++ b/frontend/src/component/common/util.js @@ -118,12 +118,11 @@ export const modalStyles = { export const updateIndexInArray = (array, index, newValue) => array.map((v, i) => (i === index ? newValue : v)); -export const showPnpsFeedback = user => { - if (!user) return; - if (!user.feedback) return; - if (user.feedback.length > 0) { - const feedback = user.feedback.find( - feedback => feedback.feedbackId === 'pnps' +export const showPnpsFeedback = (feedbackList) => { + if (!feedbackList) return; + if (feedbackList.length > 0) { + const feedback = feedbackList.find( + feedback => feedback.feedbackId === PNPS_FEEDBACK_ID ); if (!feedback) return false; @@ -143,3 +142,5 @@ export const showPnpsFeedback = user => { } return true; }; + +export const PNPS_FEEDBACK_ID = 'pnps' diff --git a/frontend/src/store/feedback/actions.js b/frontend/src/store/feedback/actions.js deleted file mode 100644 index 03c335bd73..0000000000 --- a/frontend/src/store/feedback/actions.js +++ /dev/null @@ -1,8 +0,0 @@ -export const SHOW_FEEDBACK = 'SHOW_FEEDBACK'; -export const HIDE_FEEDBACK = 'HIDE_FEEDBACK'; - -export const showFeedback = dispatch => () => dispatch({ type: SHOW_FEEDBACK }); - -export const hideFeedback = dispatch => () => { - dispatch({ type: HIDE_FEEDBACK }); -}; diff --git a/frontend/src/store/feedback/index.js b/frontend/src/store/feedback/index.js deleted file mode 100644 index 5e4a60bbdd..0000000000 --- a/frontend/src/store/feedback/index.js +++ /dev/null @@ -1,15 +0,0 @@ -import { HIDE_FEEDBACK, SHOW_FEEDBACK } from './actions'; - -const feedback = (state = {}, action) => { - switch (action.type) { - case SHOW_FEEDBACK: - return { ...state, show: true }; - case HIDE_FEEDBACK: { - return { ...state, show: false }; - } - default: - return state; - } -}; - -export default feedback; diff --git a/frontend/src/store/index.js b/frontend/src/store/index.js index 68ae07a75d..0011a0ee61 100644 --- a/frontend/src/store/index.js +++ b/frontend/src/store/index.js @@ -12,7 +12,6 @@ import uiConfig from './ui-config'; import projects from './project'; import addons from './addons'; import apiCalls from './api-calls'; -import feedback from './feedback'; const unleashStore = combineReducers({ features, @@ -28,7 +27,6 @@ const unleashStore = combineReducers({ projects, addons, apiCalls, - feedback, }); export default unleashStore;