Skip to content

Commit

Permalink
fix: revert changes warning
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikmv committed Jan 16, 2025
1 parent 617fdb7 commit b0bdad6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class ScopeSelectorClass extends Component<Props, State> {
super(props);

this.state = {
openOrgUnitWarning: false,
openProgramWarning: null,
openCatComboWarning: false,
openStartAgainWarning: false,
Expand All @@ -31,6 +32,14 @@ class ScopeSelectorClass extends Component<Props, State> {

dontShowWarning = () => !this.props.isUserInteractionInProgress;

handleOpenOrgUnitWarning = () => {
if (this.dontShowWarning()) {
this.props.onResetOrgUnitId();
return;
}
this.setState({ openOrgUnitWarning: true });
}

handleOpenProgramWarning = (baseAction: ReduxAction<any, any>) => {
if (this.dontShowWarning()) {
this.props.onResetProgramId(baseAction);
Expand All @@ -57,12 +66,18 @@ class ScopeSelectorClass extends Component<Props, State> {

handleClose = () => {
this.setState({
openOrgUnitWarning: false,
openProgramWarning: null,
openCatComboWarning: false,
openStartAgainWarning: false,
});
}

handleAcceptOrgUnit = () => {
this.props.onResetOrgUnitId();
this.handleClose();
}

handleAcceptProgram = () => {
if (this.state.openProgramWarning) {
this.props.onResetProgramId(this.state.openProgramWarning);
Expand Down Expand Up @@ -98,7 +113,7 @@ class ScopeSelectorClass extends Component<Props, State> {
onSetProgramId={onSetProgramId}
onSetCategoryOption={onSetCategoryOption}
onResetAllCategoryOptions={onResetAllCategoryOptions}
onResetOrgUnitId={this.props.onResetOrgUnitId}
onResetOrgUnitId={this.handleOpenOrgUnitWarning}
onResetProgramId={this.handleOpenProgramWarning}
onResetCategoryOption={this.handleOpenCatComboWarning}
onStartAgain={this.handleStartAgainWarning}
Expand All @@ -112,6 +127,12 @@ class ScopeSelectorClass extends Component<Props, State> {
>
{this.props.children}
</QuickSelector>
<DiscardDialog
onDestroy={this.handleAcceptOrgUnit}
open={this.state.openOrgUnitWarning}
onCancel={this.handleClose}
{...defaultDialogProps}
/>
<DiscardDialog
onDestroy={this.handleAcceptProgram}
open={!!this.state.openProgramWarning}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export type Props = {|
|}

export type State = {|
openOrgUnitWarning: boolean;
openProgramWarning: ?Object;
openCatComboWarning: boolean;
openStartAgainWarning: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ const WidgetEventEditPlain = ({
const [changeLogIsOpen, setChangeLogIsOpen] = useState(false);
// "Edit event"-button depends on loadedValues. Delay rendering component until loadedValues has been initialized.
const loadedValues = useSelector(({ viewEventPage }) => viewEventPage.loadedValues);

const { orgUnit: coreOrgUnit, error } = useCoreOrgUnit(orgUnitId);
const orgUnit = coreOrgUnit || loadedValues?.orgUnit;

Expand Down

0 comments on commit b0bdad6

Please sign in to comment.