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
64 changes: 64 additions & 0 deletions src/actions/sponsor-forms-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ export const RESET_TEMPLATE_FORM = "RESET_TEMPLATE_FORM";

export const REQUEST_SPONSOR_MANAGED_FORMS = "REQUEST_SPONSOR_MANAGED_FORMS";
export const RECEIVE_SPONSOR_MANAGED_FORMS = "RECEIVE_SPONSOR_MANAGED_FORMS";
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 REQUEST_SPONSOR_CUSTOMIZED_FORMS =
"REQUEST_SPONSOR_CUSTOMIZED_FORMS";
Expand Down Expand Up @@ -616,6 +619,40 @@ export const saveSponsorManagedForm =
});
};

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

dispatch(startLoading());

const normalizedEntity = normalizeSponsorCustomizedForm(
entity,
currentSummit.time_zone.id
);

const params = {
access_token: accessToken,
fields:
"id,code,name,is_archived,opens_at,expires_at,items_count,allowed_add_ons",
relations: "allowed_add_ons"
};

return putRequest(
null,
createAction(SPONSOR_MANAGED_FORMS_UPGRADED),
`${window.PURCHASES_API_URL}/api/v1/summits/${currentSummit.id}/sponsors/${sponsorId}/managed-forms/${entity.id}`,
normalizedEntity,
snackbarErrorHandler
)(params)(dispatch).then(() => {
dispatch(stopLoading());
});
};
Comment thread
coderabbitai[bot] marked this conversation as resolved.

const normalizeSponsorManagedForm = (entity) => {
const normalizedEntity = {
show_form_ids: entity.forms,
Expand All @@ -629,6 +666,31 @@ const normalizeSponsorManagedForm = (entity) => {
return normalizedEntity;
};

export const getSponsorManagedForm = (formId) => async (dispatch, getState) => {
const { currentSummitState } = getState();
const { currentSummit } = currentSummitState;
const accessToken = await getAccessTokenSafely();

dispatch(startLoading());

const params = {
fields:
"id,code,name,is_archived,opens_at,expires_at,items_count,allowed_add_ons",
expand:
"allowed_add_ons,meta_fields,meta_fields.values,items,items.meta_fields,items.meta_fields.values,items.images",
access_token: accessToken
};

return getRequest(
null,
createAction(RECEIVE_SPONSOR_CUSTOMIZED_FORM),
`${window.PURCHASES_API_URL}/api/v1/summits/${currentSummit.id}/show-forms/${formId}`,
snackbarErrorHandler
)(params)(dispatch).then(() => {
dispatch(stopLoading());
});
};
Comment on lines +684 to +692
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Inconsistent error handler for GET request.

All other GET requests in this file use authErrorHandler, but getSponsorManagedForm uses snackbarErrorHandler. This inconsistency could mask authentication errors that other GET actions would properly handle (e.g., redirect to login on 401).

🔧 Proposed fix
   return getRequest(
     null,
     createAction(RECEIVE_SPONSOR_CUSTOMIZED_FORM),
     `${window.PURCHASES_API_URL}/api/v1/summits/${currentSummit.id}/show-forms/${formId}`,
-    snackbarErrorHandler
+    authErrorHandler
   )(params)(dispatch).then(() => {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
return getRequest(
null,
createAction(RECEIVE_SPONSOR_CUSTOMIZED_FORM),
`${window.PURCHASES_API_URL}/api/v1/summits/${currentSummit.id}/show-forms/${formId}`,
snackbarErrorHandler
)(params)(dispatch).then(() => {
dispatch(stopLoading());
});
};
return getRequest(
null,
createAction(RECEIVE_SPONSOR_CUSTOMIZED_FORM),
`${window.PURCHASES_API_URL}/api/v1/summits/${currentSummit.id}/show-forms/${formId}`,
authErrorHandler
)(params)(dispatch).then(() => {
dispatch(stopLoading());
});
};
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/actions/sponsor-forms-actions.js` around lines 684 - 692, The GET in
getSponsorManagedForm is using snackbarErrorHandler instead of the standard
authErrorHandler; update the getRequest call that dispatches
createAction(RECEIVE_SPONSOR_CUSTOMIZED_FORM) for the URL
`${window.PURCHASES_API_URL}/api/v1/summits/${currentSummit.id}/show-forms/${formId}`
to pass authErrorHandler (matching other GETs in this file) so authentication
errors are handled consistently (e.g., 401 redirects).


/* ************************************************************************ */
/* CUSTOMIZED FORMS */
/* ************************************************************************ */
Expand Down Expand Up @@ -891,6 +953,8 @@ export const normalizeSponsorCustomizedForm = (entity, summitTZ) => {

normalizedEntity.meta_fields = meta_fields.filter((mf) => !!mf.name);

delete normalizedEntity.sponsorship_types;

return normalizedEntity;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
import CloseIcon from "@mui/icons-material/Close";
import {
getSponsorCustomizedForm,
getSponsorManagedForm,
upgradeSponsorManagedForm,
resetSponsorCustomizedForm,
saveSponsorCustomizedForm,
updateSponsorCustomizedForm
Expand All @@ -24,11 +26,14 @@ const CustomizedFormPopup = ({
sponsor,
summitId,
summitTZ,
upgradeManaged,
open,
onClose,
onSaved,
getSponsorCustomizedForm,
getSponsorManagedForm,
resetSponsorCustomizedForm,
upgradeSponsorManagedForm,
saveSponsorCustomizedForm,
updateSponsorCustomizedForm
}) => {
Expand All @@ -47,7 +52,9 @@ const CustomizedFormPopup = ({
const handleOnSave = (values) => {
if (isSaving) return;

const save = values.id
const save = upgradeManaged
? upgradeSponsorManagedForm
: values.id
? updateSponsorCustomizedForm
: saveSponsorCustomizedForm;
setIsSaving(true);
Expand All @@ -67,7 +74,11 @@ const CustomizedFormPopup = ({

useEffect(() => {
if (formId) {
getSponsorCustomizedForm(formId);
if (upgradeManaged) {
getSponsorManagedForm(formId);
} else {
getSponsorCustomizedForm(formId);
}
}
}, [formId]);
Comment on lines 75 to 83
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Missing upgradeManaged in useEffect dependency array.

The effect uses upgradeManaged to determine which fetch function to call, but it's not included in the dependency array. If upgradeManaged changes while formId remains the same, the effect won't re-run with the correct fetch logic.

🔧 Proposed fix
   useEffect(() => {
     if (formId) {
       if (upgradeManaged) {
         getSponsorManagedForm(formId);
       } else {
         getSponsorCustomizedForm(formId);
       }
     }
-  }, [formId]);
+  }, [formId, upgradeManaged]);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
useEffect(() => {
if (formId) {
getSponsorCustomizedForm(formId);
if (upgradeManaged) {
getSponsorManagedForm(formId);
} else {
getSponsorCustomizedForm(formId);
}
}
}, [formId]);
useEffect(() => {
if (formId) {
if (upgradeManaged) {
getSponsorManagedForm(formId);
} else {
getSponsorCustomizedForm(formId);
}
}
}, [formId, upgradeManaged]);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/pages/sponsors/sponsor-page/tabs/sponsor-forms-tab/components/customized-form/customized-form-popup.js`
around lines 75 - 83, The useEffect in customized-form-popup.js depends on both
formId and upgradeManaged but only lists formId; update the dependency array for
the useEffect that calls getSponsorManagedForm(formId) or
getSponsorCustomizedForm(formId) to include upgradeManaged so the effect re-runs
when upgradeManaged changes (e.g., change useEffect(..., [formId]) to
useEffect(..., [formId, upgradeManaged])); also ensure
getSponsorManagedForm/getSponsorCustomizedForm are stable or added to the
dependency array if they are not memoized.


Expand Down Expand Up @@ -125,6 +136,8 @@ const mapStateToProps = ({
export default connect(mapStateToProps, {
resetSponsorCustomizedForm,
getSponsorCustomizedForm,
getSponsorManagedForm,
upgradeSponsorManagedForm,
saveSponsorCustomizedForm,
updateSponsorCustomizedForm
})(CustomizedFormPopup);
31 changes: 28 additions & 3 deletions src/pages/sponsors/sponsor-page/tabs/sponsor-forms-tab/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const SponsorFormsTab = ({
}) => {
const [openPopup, setOpenPopup] = useState(null);
const [customFormEdit, setCustomFormEdit] = useState(null);
const [upgradeManaged, setUpgradeManaged] = useState(false);

useEffect(() => {
getSponsorManagedForms();
Expand Down Expand Up @@ -102,7 +103,8 @@ const SponsorFormsTab = ({
};

const handleCustomizeForm = (item) => {
console.log("CUSTOMIZE : ", item);
setUpgradeManaged(true);
setCustomFormEdit(item);
};

const handleArchiveForm = (item) =>
Expand Down Expand Up @@ -157,7 +159,8 @@ const SponsorFormsTab = ({
);
};

const handleSaveFormFromTemplate = (entity) => saveSponsorManagedForm(entity).then(() => {
const handleSaveFormFromTemplate = (entity) =>
saveSponsorManagedForm(entity).then(() => {
const { perPage, order, orderDir } = managedForms;
getSponsorManagedForms(
term,
Expand Down Expand Up @@ -187,6 +190,27 @@ const SponsorFormsTab = ({
);
};

const handleCloseCustomizedPopup = () => {
setCustomFormEdit(null);
setUpgradeManaged(false);
getSponsorManagedForms(
term,
DEFAULT_CURRENT_PAGE,
managedForms.perPage,
managedForms.order,
managedForms.orderDir,
hideArchived
);
getSponsorCustomizedForms(
term,
DEFAULT_CURRENT_PAGE,
customizedForms.perPage,
customizedForms.order,
customizedForms.orderDir,
hideArchived
);
};

const baseColumns = (name, manageItemsFn) => [
{
columnKey: "name",
Expand Down Expand Up @@ -399,7 +423,8 @@ const SponsorFormsTab = ({
<CustomizedFormPopup
formId={customFormEdit?.id || null}
open={!!customFormEdit}
onClose={() => setCustomFormEdit(null)}
upgradeManaged={upgradeManaged}
onClose={handleCloseCustomizedPopup}
onSaved={handleCustomizedFormSaved}
sponsor={sponsor}
summitId={currentSummit.id}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
deleteSponsorManagedPage,
unarchiveCustomizedPage,
archiveCustomizedPage,
resetSponsorPage,
resetSponsorPage
} from "../../../../../actions/sponsor-pages-actions";
import CustomAlert from "../../../../../components/mui/custom-alert";
import SearchInput from "../../../../../components/mui/search-input";
Expand Down Expand Up @@ -196,7 +196,6 @@ const SponsorPagesTab = ({
console.log("ARCHIVE MANAGED ", item);

const handleManagedEdit = (item) => {
console.log("CHECK!", item);
getSponsorManagedPage(item.id).then(() => setOpenPopup("managedPagePopup"));
};

Expand Down
Loading