Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/actions/sponsor-forms-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ export const REQUEST_SPONSOR_MANAGED_FORM = "REQUEST_SPONSOR_MANAGED_FORM";
export const RECEIVE_SPONSOR_MANAGED_FORM = "RECEIVE_SPONSOR_MANAGED_FORM";
export const SPONSOR_MANAGED_FORMS_ADDED = "SPONSOR_MANAGED_FORMS_ADDED";
export const SPONSOR_MANAGED_FORMS_UPGRADED = "SPONSOR_MANAGED_FORMS_UPGRADED";
export const SPONSOR_MANAGED_FORMS_OVERRIDEN =
"SPONSOR_MANAGED_FORMS_OVERRIDEN";

export const REQUEST_SPONSOR_CUSTOMIZED_FORMS =
"REQUEST_SPONSOR_CUSTOMIZED_FORMS";
Expand Down Expand Up @@ -622,6 +624,37 @@ export const saveSponsorManagedForm =
});
};

export const overrideSponsorManagedForm =
(formId) => async (dispatch, getState) => {
const { currentSummitState, currentSponsorState } = getState();
const { currentSummit } = currentSummitState;
const {
entity: { id: sponsorId }
} = currentSponsorState;
const accessToken = await getAccessTokenSafely();

dispatch(startLoading());

const params = {
access_token: accessToken
};

return postRequest(
null,
createAction(SPONSOR_MANAGED_FORMS_OVERRIDEN),
`${window.PURCHASES_API_URL}/api/v1/summits/${currentSummit.id}/sponsors/${sponsorId}/managed-forms/${formId}/override`,
{},
snackbarErrorHandler
)(params)(dispatch)
.then(() => {
dispatch(getSponsorManagedForms());
dispatch(getSponsorCustomizedForms());
Comment on lines +649 to +651

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Preserve the active table queries during refresh.

These default-argument calls reset both tables to page 1, default sorting, an empty search, and showArchived=false after an override. Refresh using the current managed/customized table parameters, as the UI handlers do, so an override does not move users out of their current view.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/actions/sponsor-forms-actions.js` around lines 649 - 651, Update the
refresh success handler containing getSponsorManagedForms and
getSponsorCustomizedForms to dispatch both actions with the current managed and
customized table parameters, matching the parameter construction used by the UI
handlers. Preserve each table’s page, sorting, search, and showArchived state
instead of invoking the default-argument forms.

})
.finally(() => {
dispatch(stopLoading());
});
};

export const upgradeSponsorManagedForm =
(entity) => async (dispatch, getState) => {
const { currentSummitState, currentSponsorState } = getState();
Expand Down
2 changes: 2 additions & 0 deletions src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2516,13 +2516,15 @@
"items": "Items",
"managed_forms": "Managed Forms",
"manage_items": "Manage Items",
"override": "Override",
"none": "None",
"customize": "Customize",
"archive": "Archive",
"unarchive": "Unarchive",
"add_form_using_template": "Add Form Using Template",
"add_selected_form_template": "Add Selected Form Template",
"customized": "CUSTOMIZED",
"override_warning": "By overriding this Managed Form, a new Customized Form will be created. Are you sure you want to proceed?",
"customized_form": {
"new_form_title": "Create New Form",
"edit_form_title": "Edit Form",
Expand Down
70 changes: 49 additions & 21 deletions src/pages/sponsors/sponsor-page/tabs/sponsor-forms-tab/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ import {
getSponsorCustomizedForms,
getSponsorManagedForms,
saveSponsorManagedForm,
overrideSponsorManagedForm,
unarchiveSponsorCustomizedForm
} from "../../../../../actions/sponsor-forms-actions";
import CustomAlert from "../../../../../components/mui/custom-alert";
import AddSponsorFormTemplatePopup from "./components/add-sponsor-form-template-popup";
import CustomizedFormPopup from "./components/customized-form/customized-form-popup";
import { DEFAULT_CURRENT_PAGE } from "../../../../../utils/constants";
import showConfirmDialog from "../../../../../components/mui/showConfirmDialog";

const SponsorFormsTab = ({
term,
Expand All @@ -51,6 +53,7 @@ const SponsorFormsTab = ({
getSponsorManagedForms,
getSponsorCustomizedForms,
saveSponsorManagedForm,
overrideSponsorManagedForm,
archiveSponsorCustomizedForm,
unarchiveSponsorCustomizedForm,
deleteSponsorCustomizedForm
Expand Down Expand Up @@ -157,8 +160,15 @@ const SponsorFormsTab = ({
);
};

const handleManagedFormManageItems = (item) => {
console.log("Managed Form Item Edit : ", item);
const handleOverrideForm = async (form) => {
const confirmed = await showConfirmDialog({
title: T.translate("general.are_you_sure"),
text: T.translate("edit_sponsor.forms_tab.override_warning")
});

if (confirmed) {
overrideSponsorManagedForm(form.id);
}
};

const handleCustomizedEdit = (item) => {
Expand Down Expand Up @@ -257,12 +267,12 @@ const SponsorFormsTab = ({
);
};

const baseColumns = (name, manageItemsFn) => [
const baseColumns = (name) => [
{
columnKey: "name",
header: name,
sortable: true,
width: 235,
width: 250,
render: (row) =>
row.original_show_form_id > 0 ? (
<>
Expand Down Expand Up @@ -316,9 +326,13 @@ const SponsorFormsTab = ({
? T.translate("edit_sponsor.forms_tab.item")
: T.translate("edit_sponsor.forms_tab.items")
}`
},
}
];

const managedFormsColumns = [
...baseColumns(T.translate("edit_sponsor.forms_tab.managed_forms")),
{
columnKey: "manage_items",
columnKey: "override",
header: "",
align: "left",
width: 130,
Expand All @@ -332,19 +346,12 @@ const SponsorFormsTab = ({
fontSize: "13px",
fontWeight: "normal"
}}
onClick={() => manageItemsFn(row)}
onClick={() => handleOverrideForm(row)}
>
{T.translate("edit_sponsor.forms_tab.manage_items")}
{T.translate("edit_sponsor.forms_tab.override")}
</Button>
)
}
];

const managedFormsColumns = [
...baseColumns(
T.translate("edit_sponsor.forms_tab.managed_forms"),
handleManagedFormManageItems
),
},
{
columnKey: "archive",
header: "",
Expand All @@ -354,13 +361,13 @@ const SponsorFormsTab = ({
{
columnKey: "customize",
header: "",
width: 100,
width: 120,
align: "center",
render: (row) => (
<Button
variant="text"
color="inherit"
size="medium"
size="small"
sx={{ px: 0, color: "rgba(0,0,0,0.56)", fontWeight: "normal" }}
onClick={() => handleCustomizeForm(row)}
>
Expand All @@ -374,9 +381,29 @@ const SponsorFormsTab = ({

const customizedFormsColumns = [
...baseColumns(
T.translate("edit_sponsor.forms_tab.sponsor_customized_forms"),
handleCustomizedFormManageItems
)
T.translate("edit_sponsor.forms_tab.sponsor_customized_forms")
),
{
columnKey: "manage_items",
header: "",
align: "left",
width: 130,
render: (row) => (
<Button
variant="text"
size="small"
sx={{
padding: 0,
color: "rgba(0,0,0,0.56)",
fontSize: "13px",
fontWeight: "normal"
}}
onClick={() => handleCustomizedFormManageItems(row)}
>
{T.translate("edit_sponsor.forms_tab.manage_items")}
</Button>
)
}
];

return (
Expand Down Expand Up @@ -522,6 +549,7 @@ const mapStateToProps = ({
export default connect(mapStateToProps, {
getSponsorManagedForms,
saveSponsorManagedForm,
overrideSponsorManagedForm,
getSponsorCustomizedForms,
archiveSponsorCustomizedForm,
unarchiveSponsorCustomizedForm,
Expand Down
Loading