Skip to content

Commit

Permalink
bugfix: fix ExpandedModal proptype warning (#1348)
Browse files Browse the repository at this point in the history
Co-authored-by: Peter Shih <[email protected]>
  • Loading branch information
mark86092 and peteranny authored Jun 19, 2024
1 parent 17dcddf commit 5201cac
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
13 changes: 7 additions & 6 deletions src/components/App/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import StaticHelmet from 'common/StaticHelmet';
import LoginModal from 'common/LoginModal';
import useLocStateToastObserver from 'hooks/toastNotification/useLocStateToastObserver';
import { STATE_SHARE } from 'common/ShareExpSection/shareLinkTo';

import CollapsedDrawer from 'common/Questionnaire/CollapsedDrawer';
import ExpandedModal from 'common/Questionnaire/ExpandedModal';
import ToastNotification from '../ToastNotification/ToastNotification';
import { AppRouteWithSubRoutes } from '../route';
import styles from './App.module.css';
Expand All @@ -15,8 +16,6 @@ import Footer from './Footer';
import ShareInterviewModal from '../ShareExperience/InterviewForm/TypeForm';
import ShareSalaryWorkTimesModal from '../ShareExperience/TimeSalaryForm/TypeForm';
import routes from '../../routes';
import CollapsedDrawer from 'common/Questionnaire/CollapsedDrawer';
import NetPromoter from 'common/Questionnaire/ExpandedModal';

const useShare = () => {
const location = useLocation();
Expand Down Expand Up @@ -64,9 +63,11 @@ const App = () => {
hideProgressBar={share === STATE_SHARE.SALARY_WORK_TIME_NO_PROGRESS_BAR}
/>
<LoginModal />
<CollapsedDrawer>
<NetPromoter />
</CollapsedDrawer>
<CollapsedDrawer
render={({ handleToggleModalOpen }) => (
<ExpandedModal handleToggleModalOpen={handleToggleModalOpen} />
)}
/>
</Fragment>
);
};
Expand Down
16 changes: 9 additions & 7 deletions src/components/common/Questionnaire/CollapsedDrawer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useDispatch, useSelector } from 'react-redux';

const MILLISECONDS_OF_TWO_SUBMISSION_SPAN = 1000 * 60 * 60 * 24 * 30;

const CollapsedDrawer = ({ title = '給我們回饋', children }) => {
const CollapsedDrawer = ({ title, render }) => {
const isOpen = useSelector(state => state.questionnaireExpandedModal.isOpen);
const dispatch = useDispatch();
const handleToggleModalOpen = useCallback(() => {
Expand All @@ -30,11 +30,9 @@ const CollapsedDrawer = ({ title = '給我們回饋', children }) => {
}
}

const childrenWithProps = React.Children.map(children, child =>
React.cloneElement(child, { handleToggleModalOpen }),
);

if (isOpen) return childrenWithProps;
if (isOpen) {
return render({ handleToggleModalOpen });
}

return (
<div className={styles.container} onClick={handleToggleModalOpen}>
Expand All @@ -44,8 +42,12 @@ const CollapsedDrawer = ({ title = '給我們回饋', children }) => {
};

CollapsedDrawer.propTypes = {
children: PropTypes.node.isRequired,
render: PropTypes.func.isRequired,
title: PropTypes.string,
};

CollapsedDrawer.defaultProps = {
title: '給我們回饋',
};

export default CollapsedDrawer;

0 comments on commit 5201cac

Please sign in to comment.