Skip to content

Commit 838fe96

Browse files
Merge pull request #3831 from OneCommunityGlobal/sundar/fix-save-summary
Sundar/fix save summary
2 parents 856ae3d + 119c8f5 commit 838fe96

2 files changed

Lines changed: 25 additions & 15 deletions

File tree

src/components/WeeklySummary/WeeklySummary.jsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable prettier/prettier */
21
import { Component } from 'react';
32
import PropTypes from 'prop-types';
43
import {
@@ -623,10 +622,14 @@ export class WeeklySummary extends Component {
623622

624623
// Updates user profile and weekly summaries
625624
updateUserData = async userId => {
626-
// eslint-disable-next-line no-shadow
627625
const { getUserProfile, getWeeklySummaries } = this.props;
628-
await getUserProfile(userId);
629-
await getWeeklySummaries(userId);
626+
if (typeof getUserProfile === 'function') {
627+
await getUserProfile(userId);
628+
}
629+
// always refresh summaries if that exists
630+
if (typeof getWeeklySummaries === 'function') {
631+
await getWeeklySummaries(userId);
632+
}
630633
};
631634

632635
// Handler for success scenario after save
@@ -654,15 +657,15 @@ export class WeeklySummary extends Component {
654657
const toastIdOnSave = 'toast-on-save';
655658
const errors = this.validate();
656659

657-
this.setState({ errors: errors || {} });
660+
this.setState({ errors: errors });
658661
if (Object.keys(errors).length > 0) {
659662
this.setState({ moveConfirm: false });
660663
return;
661664
}
662665

663666
const result = await this.handleChangeInSummary();
664667

665-
if (result === 200) {
668+
if (result === 200 || result?.status === 200) {
666669
await this.handleSaveSuccess(toastIdOnSave);
667670
if (closeAfterSave) {
668671
this.handleClose();
@@ -712,10 +715,10 @@ export class WeeklySummary extends Component {
712715
}
713716
this.mainSaveHandler(true);
714717
};
715-
716718
handleClose = () => {
717-
// eslint-disable-next-line react/destructuring-assignment
718-
this.props.setPopup(false);
719+
if (typeof this.props.setPopup === 'function') {
720+
this.props.setPopup(false);
721+
}
719722
};
720723

721724
render() {

src/components/WeeklySummary/__tests__/WeeklySummary.test.jsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/* eslint-disable testing-library/no-render-in-lifecycle */
2-
// eslint-disable-next-line no-unused-vars
32
import React from 'react';
43
import moment from 'moment';
54
import { render, screen, waitFor, fireEvent } from '@testing-library/react';
@@ -19,13 +18,21 @@ vi.mock('../CurrentPromptModal', () => ({
1918
default: () => <div data-testid="current-prompt-modal">Mocked Prompt Modal</div>,
2019
}));
2120
const wrapper = props => render(<CurrentPromptModal {...props} />);
22-
vi.mock('react-toastify', () => ({
23-
toast: vi.fn(),
24-
ToastContainer: () => <div data-testid="toast-container" />,
25-
}));
21+
22+
vi.mock('react-toastify', () => {
23+
const toast = vi.fn();
24+
toast.success = vi.fn();
25+
toast.error = vi.fn();
26+
27+
return {
28+
toast,
29+
ToastContainer: () => <div data-testid="toast-container" />,
30+
};
31+
});
32+
2633
const mockStore = configureStore([]);
2734

28-
describe.skip('WeeklySummary page', () => {
35+
describe('WeeklySummary page', () => {
2936
describe('On page load', () => {
3037
it('displays loading indicator', () => {
3138
const props = {

0 commit comments

Comments
 (0)