Skip to content
Open
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
107 changes: 78 additions & 29 deletions src/actions/sponsor-cart-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
createAction,
getRequest,
deleteRequest,
putRequest,
startLoading,
stopLoading
} from "openstack-uicore-foundation/lib/utils/actions";
Expand All @@ -28,6 +29,7 @@ import { ERROR_CODE_404 } from "../utils/constants";
export const REQUEST_SPONSOR_CART = "REQUEST_SPONSOR_CART";
export const RECEIVE_SPONSOR_CART = "RECEIVE_SPONSOR_CART";
export const SPONSOR_CART_FORM_DELETED = "SPONSOR_CART_FORM_DELETED";
export const SPONSOR_CART_FORM_LOCKED = "SPONSOR_CART_FORM_LOCKED";

const customErrorHandler = (err, res) => (dispatch, state) => {
const code = err.status;
Expand Down Expand Up @@ -82,35 +84,82 @@ export const getSponsorCart =
});
};

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

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

dispatch(startLoading());
return deleteRequest(
null,
createAction(SPONSOR_CART_FORM_DELETED)({ formId }),
`${window.PURCHASES_API_URL}/api/v1/summits/${currentSummit.id}/sponsors/${sponsorId}/carts/current/forms/${formId}`,
null,
snackbarErrorHandler
)(params)(dispatch)
.then(() => {
getSponsorCart()(dispatch, getState);
dispatch(
snackbarSuccessHandler({
title: T.translate("general.success"),
html: T.translate("sponsor_forms.form_delete_success")
})
);
})
.finally(() => {
dispatch(stopLoading());
});
};

return deleteRequest(
null,
createAction(SPONSOR_CART_FORM_DELETED)({ formId }),
`${window.PURCHASES_API_URL}/api/v1/summits/${currentSummit.id}/sponsors/${sponsorId}/sponsor-forms/${formId}`,
null,
snackbarErrorHandler
)(params)(dispatch)
.then(() => {
dispatch(
snackbarSuccessHandler({
title: T.translate("general.success"),
html: T.translate("sponsor_forms.form_delete_success")
})
);
})
.finally(() => {
dispatch(stopLoading());
});
};
export const lockSponsorCartForm = (formId) => async (dispatch, getState) => {
const { currentSummitState, currentSponsorState } = getState();
const { currentSummit } = currentSummitState;
const { entity: sponsor } = currentSponsorState;

const accessToken = await getAccessTokenSafely();

const params = {
access_token: accessToken
};

dispatch(startLoading());

putRequest(
null,
createAction(SPONSOR_CART_FORM_LOCKED)({ formId, locked: true }),
`${window.SPONSOR_USERS_API_URL}/api/v1/shows/${currentSummit.id}/sponsors/${sponsor.id}/carts/current/forms/${formId}/lock`,
{},
snackbarErrorHandler
)(params)(dispatch)
.catch(console.log) // need to catch promise reject
.finally(() => {
dispatch(stopLoading());
});
};
Comment on lines +119 to +143
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Missing return statement for the promise.

lockSponsorCartForm does not return the promise, unlike deleteSponsorCartForm and unlockSponsorCartForm. This prevents callers from chaining or awaiting the operation.

Proposed fix
   dispatch(startLoading());

-  putRequest(
+  return putRequest(
     null,
     createAction(SPONSOR_CART_FORM_LOCKED)({ formId, locked: true }),
🤖 Prompt for AI Agents
In @src/actions/sponsor-cart-actions.js around lines 119 - 143,
lockSponsorCartForm currently dispatches the putRequest promise but does not
return it, preventing callers from awaiting or chaining; update
lockSponsorCartForm to return the putRequest(...) invocation (the same
expression ending with (params)(dispatch)) so the function returns the promise
chain and retains the existing .catch/.finally behavior; locate the
lockSponsorCartForm export and add the return in front of the putRequest call.


export const unlockSponsorCartForm = (formId) => async (dispatch, getState) => {
const { currentSummitState, currentSponsorState } = getState();
const { currentSummit } = currentSummitState;
const { entity: sponsor } = currentSponsorState;
const accessToken = await getAccessTokenSafely();
const params = { access_token: accessToken };

dispatch(startLoading());

return deleteRequest(
null,
createAction(SPONSOR_CART_FORM_LOCKED)({ formId, locked: false }),
`${window.SPONSOR_USERS_API_URL}/api/v1/shows/${currentSummit.id}/sponsors/${sponsor.id}/carts/current/forms/${formId}/lock`,
null,
snackbarErrorHandler
)(params)(dispatch)
.catch(console.log) // need to catch promise reject
.finally(() => {
dispatch(stopLoading());
});
};
20 changes: 15 additions & 5 deletions src/pages/sponsors/sponsor-cart-tab/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ import LockClosedIcon from "@mui/icons-material/Lock";
import AddIcon from "@mui/icons-material/Add";
import {
deleteSponsorCartForm,
getSponsorCart
getSponsorCart,
lockSponsorCartForm,
unlockSponsorCartForm
} from "../../../actions/sponsor-cart-actions";
import SearchInput from "../../../components/mui/search-input";
import { TotalRow } from "../../../components/mui/table/extra-rows";
Expand All @@ -39,7 +41,9 @@ const SponsorCartTab = ({
sponsor,
summitId,
getSponsorCart,
deleteSponsorCartForm
deleteSponsorCartForm,
lockSponsorCartForm,
unlockSponsorCartForm
}) => {
const [openPopup, setOpenPopup] = useState(null);
const [formEdit, setFormEdit] = useState(null);
Expand All @@ -64,8 +68,12 @@ const SponsorCartTab = ({
deleteSponsorCartForm(itemId);
};

const handleLock = (item) => {
console.log("LOCK : ", item);
const handleLock = (form) => {
if (form.is_locked) {
unlockSponsorCartForm(form.form_id);
} else {
lockSponsorCartForm(form.form_id);
}
};

const handlePayCreditCard = () => {
Expand Down Expand Up @@ -227,5 +235,7 @@ const mapStateToProps = ({ sponsorPageCartListState }) => ({

export default connect(mapStateToProps, {
getSponsorCart,
deleteSponsorCartForm
deleteSponsorCartForm,
lockSponsorCartForm,
unlockSponsorCartForm
})(SponsorCartTab);
21 changes: 20 additions & 1 deletion src/reducers/sponsors/sponsor-page-cart-list-reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import { SET_CURRENT_SUMMIT } from "../../actions/summit-actions";
import {
REQUEST_SPONSOR_CART,
RECEIVE_SPONSOR_CART,
SPONSOR_CART_FORM_DELETED
SPONSOR_CART_FORM_DELETED,
SPONSOR_CART_FORM_LOCKED
} from "../../actions/sponsor-cart-actions";

const DEFAULT_STATE = {
Expand Down Expand Up @@ -70,6 +71,24 @@ const sponsorPageCartListReducer = (state = DEFAULT_STATE, action) => {
}
};
}
case SPONSOR_CART_FORM_LOCKED: {
const { formId, locked } = payload;

const forms = state.cart.forms.map((form) => {
if (form.form_id === formId) {
return {...form, locked};
}
return form;
});

return {
...state,
cart: {
...state.cart,
forms
}
};
}
Comment on lines +74 to +91
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check how form objects are structured and which ID property is used
rg -n "form\.id|form\.form_id|form_id|is_locked" --type=js -C2 src/

Repository: fntechgit/summit-admin

Length of output: 5263


🏁 Script executed:

#!/bin/bash
# Get the exact code for both cart form cases to confirm the issue
sed -n '62,91p' src/reducers/sponsors/sponsor-page-cart-list-reducer.js

Repository: fntechgit/summit-admin

Length of output: 693


Fix critical property name inconsistencies causing UI state mismatch.

Two critical issues require correction:

  1. ID property inconsistency: SPONSOR_CART_FORM_DELETED (line 64) uses form.id while SPONSOR_CART_FORM_LOCKED (line 78) uses form.form_id. Since the UI dispatches actions with form.form_id, both cases should use form.form_id for consistency.

  2. Lock state property mismatch: The reducer sets locked but the UI component reads is_locked (lines 72, 133). The lock state changes will not be reflected in the UI until this is corrected to is_locked.

Proposed fix
    case SPONSOR_CART_FORM_DELETED: {
      const { formId } = payload;
-     const forms = state.cart.forms.filter((form) => form.id !== formId);
+     const forms = state.cart.forms.filter((form) => form.form_id !== formId);

      return {
        ...state,
        cart: {
          ...state.cart,
          forms
        }
      };
    }
    case SPONSOR_CART_FORM_LOCKED: {
      const { formId, locked } = payload;

      const forms = state.cart.forms.map((form) => {
        if (form.form_id === formId) {
-         return {...form, locked};
+         return {...form, is_locked: locked};
         }
         return form;
       });
🤖 Prompt for AI Agents
In @src/reducers/sponsors/sponsor-page-cart-list-reducer.js around lines 74 -
91, The reducer branch for SPONSOR_CART_FORM_LOCKED is inconsistent with other
branches and the UI: update the mapping in the SPONSOR_CART_FORM_LOCKED case to
compare against form.form_id (not form.id) and set the lock flag on the form
object as is_locked instead of locked; e.g., in the forms = state.cart.forms.map
callback for SPONSOR_CART_FORM_LOCKED return {...form, is_locked: locked} when
form.form_id === formId so the UI reads the updated property, keeping
SPONSOR_CART_FORM_DELETED and other cases using form.form_id for ID comparisons.

default:
return state;
}
Expand Down