Skip to content

Commit

Permalink
[#3688] Add confirmation popup when switching to v2
Browse files Browse the repository at this point in the history
  • Loading branch information
Viicos committed Feb 15, 2024
1 parent 86ff8a2 commit abd4929
Showing 1 changed file with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ const ObjectsApiOptionsFormFields = ({index, name, schema, formData, onChange})
const [availableObjecttypes, setAvailableObjecttypes] = useState([]);
const [availableObjecttypeVersions, setAvailableObjecttypeVersions] = useState([]);

const v2SwitchMessage = intl.formatMessage({
defaultMessage: `Switching to the new registration options will remove the existing JSON templates.
You will also not be able to save the form until the variables are correctly mapped.
Are you sure you want to continue?
`,
description: 'V2 Switch warning message',
});

const {
version = 1,
objecttype = '',
Expand All @@ -55,14 +63,20 @@ const ObjectsApiOptionsFormFields = ({index, name, schema, formData, onChange})
} = formData;

const changeVersion = index => {
if (index === 1) {
const confirmV2Switch = window.confirm(v2SwitchMessage);
if (!confirmV2Switch) return;
}

onChange(
produce(formData, draft => {
draft.objecttype = '';
draft.objecttypeVersion = '';
draft.contentJson = '';
draft.paymentStatusUpdateJson = '';
draft.version = index + 1;
})
);
if (version === 2) {
// open modal
}
};

const onFieldChange = event => {
Expand Down Expand Up @@ -114,7 +128,7 @@ const ObjectsApiOptionsFormFields = ({index, name, schema, formData, onChange})

return (
<>
<Tabs onSelect={changeVersion}>
<Tabs selectedIndex={version - 1} onSelect={changeVersion}>
<TabList>
<Tab>
<FormattedMessage
Expand Down

0 comments on commit abd4929

Please sign in to comment.