1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-05-03 01:18:43 +02:00

refactor: remove unused feedback state (#682)

* refactor: remove unused feedback state

* refactor: use PNPS feedback display logic
This commit is contained in:
olav 2022-02-09 14:06:20 +01:00 committed by GitHub
parent 93aa1ab8b8
commit b291515fa4
6 changed files with 16 additions and 45 deletions

View File

@ -23,7 +23,6 @@ import ToastRenderer from './common/ToastRenderer/ToastRenderer';
interface IAppProps extends RouteComponentProps { interface IAppProps extends RouteComponentProps {
user: IAuthStatus; user: IAuthStatus;
fetchUiBootstrap: any; fetchUiBootstrap: any;
feedback: any;
} }
const App = ({ location, user, fetchUiBootstrap }: IAppProps) => { const App = ({ location, user, fetchUiBootstrap }: IAppProps) => {
// because we need the userId when the component load. // because we need the userId when the component load.
@ -135,7 +134,6 @@ const App = ({ location, user, fetchUiBootstrap }: IAppProps) => {
<Redirect to="/404" /> <Redirect to="/404" />
</Switch> </Switch>
<Feedback <Feedback
feedbackId="pnps"
openUrl="http://feedback.unleash.run" openUrl="http://feedback.unleash.run"
/> />
</LayoutPicker> </LayoutPicker>
@ -147,10 +145,10 @@ const App = ({ location, user, fetchUiBootstrap }: IAppProps) => {
</SWRProvider> </SWRProvider>
); );
}; };
// Set state to any for now, to avoid typing up entire state object while converting to tsx. // Set state to any for now, to avoid typing up entire state object while converting to tsx.
const mapStateToProps = (state: any) => ({ const mapStateToProps = (state: any) => ({
user: state.user.toJS(), user: state.user.toJS(),
feedback: state.feedback,
}); });
export default connect(mapStateToProps)(App); export default connect(mapStateToProps)(App);

View File

@ -9,24 +9,21 @@ import { useStyles } from './Feedback.styles';
import AnimateOnMount from '../AnimateOnMount/AnimateOnMount'; import AnimateOnMount from '../AnimateOnMount/AnimateOnMount';
import ConditionallyRender from '../ConditionallyRender'; import ConditionallyRender from '../ConditionallyRender';
import { formatApiPath } from '../../../utils/format-path'; import { formatApiPath } from '../../../utils/format-path';
import { Action, Dispatch } from 'redux';
import UIContext from '../../../contexts/UIContext'; import UIContext from '../../../contexts/UIContext';
import useUser from '../../../hooks/api/getters/useUser/useUser'; import useUser from '../../../hooks/api/getters/useUser/useUser';
import { PNPS_FEEDBACK_ID, showPnpsFeedback } from '../util';
interface IFeedbackProps { interface IFeedbackProps {
show?: boolean;
hideFeedback: () => Dispatch<Action>;
fetchUser: () => void;
feedbackId: string;
openUrl: string; openUrl: string;
} }
const Feedback = ({ feedbackId, openUrl }: IFeedbackProps) => { const Feedback = ({ openUrl }: IFeedbackProps) => {
const { showFeedback, setShowFeedback } = useContext(UIContext); const { showFeedback, setShowFeedback } = useContext(UIContext);
const { refetch, feedback } = useUser(); const { refetch, feedback } = useUser();
const [answeredNotNow, setAnsweredNotNow] = useState(false); const [answeredNotNow, setAnsweredNotNow] = useState(false);
const styles = useStyles(); const styles = useStyles();
const commonStyles = useCommonStyles(); const commonStyles = useCommonStyles();
const feedbackId = PNPS_FEEDBACK_ID;
const onConfirm = async () => { const onConfirm = async () => {
const url = formatApiPath('api/admin/feedback'); const url = formatApiPath('api/admin/feedback');
@ -41,7 +38,8 @@ const Feedback = ({ feedbackId, openUrl }: IFeedbackProps) => {
body: JSON.stringify({ feedbackId }), body: JSON.stringify({ feedbackId }),
}); });
await refetch(); await refetch();
} catch { } catch (err) {
console.warn(err);
setShowFeedback(false); setShowFeedback(false);
} }
@ -68,7 +66,8 @@ const Feedback = ({ feedbackId, openUrl }: IFeedbackProps) => {
body: JSON.stringify({ feedbackId, neverShow: true }), body: JSON.stringify({ feedbackId, neverShow: true }),
}); });
await refetch(); await refetch();
} catch { } catch (err) {
console.warn(err);
setShowFeedback(false); setShowFeedback(false);
} }
@ -77,9 +76,7 @@ const Feedback = ({ feedbackId, openUrl }: IFeedbackProps) => {
}, 100); }, 100);
}; };
const pnps = feedback.find(feedback => feedback.feedbackId === feedbackId); if (!showPnpsFeedback(feedback)) {
if (pnps?.given || pnps?.neverShow) {
return null; return null;
} }

View File

@ -118,12 +118,11 @@ export const modalStyles = {
export const updateIndexInArray = (array, index, newValue) => export const updateIndexInArray = (array, index, newValue) =>
array.map((v, i) => (i === index ? newValue : v)); array.map((v, i) => (i === index ? newValue : v));
export const showPnpsFeedback = user => { export const showPnpsFeedback = (feedbackList) => {
if (!user) return; if (!feedbackList) return;
if (!user.feedback) return; if (feedbackList.length > 0) {
if (user.feedback.length > 0) { const feedback = feedbackList.find(
const feedback = user.feedback.find( feedback => feedback.feedbackId === PNPS_FEEDBACK_ID
feedback => feedback.feedbackId === 'pnps'
); );
if (!feedback) return false; if (!feedback) return false;
@ -143,3 +142,5 @@ export const showPnpsFeedback = user => {
} }
return true; return true;
}; };
export const PNPS_FEEDBACK_ID = 'pnps'

View File

@ -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 });
};

View File

@ -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;

View File

@ -12,7 +12,6 @@ import uiConfig from './ui-config';
import projects from './project'; import projects from './project';
import addons from './addons'; import addons from './addons';
import apiCalls from './api-calls'; import apiCalls from './api-calls';
import feedback from './feedback';
const unleashStore = combineReducers({ const unleashStore = combineReducers({
features, features,
@ -28,7 +27,6 @@ const unleashStore = combineReducers({
projects, projects,
addons, addons,
apiCalls, apiCalls,
feedback,
}); });
export default unleashStore; export default unleashStore;