mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-22 19:07:54 +01:00
refactor: remove unused feedback state (#682)
* refactor: remove unused feedback state * refactor: use PNPS feedback display logic
This commit is contained in:
parent
93aa1ab8b8
commit
b291515fa4
@ -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) => {
|
||||
<Redirect to="/404" />
|
||||
</Switch>
|
||||
<Feedback
|
||||
feedbackId="pnps"
|
||||
openUrl="http://feedback.unleash.run"
|
||||
/>
|
||||
</LayoutPicker>
|
||||
@ -147,10 +145,10 @@ const App = ({ location, user, fetchUiBootstrap }: IAppProps) => {
|
||||
</SWRProvider>
|
||||
);
|
||||
};
|
||||
|
||||
// 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);
|
||||
|
@ -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<Action>;
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -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'
|
||||
|
@ -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 });
|
||||
};
|
@ -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;
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user