-
Notifications
You must be signed in to change notification settings - Fork 4
feat: WIP allow to upgrade manage forms to customized #886
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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"; | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -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()); | ||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| const normalizeSponsorManagedForm = (entity) => { | ||||||||||||||||||||||||||||||||||||||
| const normalizedEntity = { | ||||||||||||||||||||||||||||||||||||||
| show_form_ids: entity.forms, | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inconsistent error handler for GET request. All other GET requests in this file use 🔧 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
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| /* ************************************************************************ */ | ||||||||||||||||||||||||||||||||||||||
| /* CUSTOMIZED FORMS */ | ||||||||||||||||||||||||||||||||||||||
| /* ************************************************************************ */ | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -891,6 +953,8 @@ export const normalizeSponsorCustomizedForm = (entity, summitTZ) => { | |||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| normalizedEntity.meta_fields = meta_fields.filter((mf) => !!mf.name); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| delete normalizedEntity.sponsorship_types; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| return normalizedEntity; | ||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -12,6 +12,8 @@ import { | |||||||||||||||||||||||||||||||||||||||
| import CloseIcon from "@mui/icons-material/Close"; | ||||||||||||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||||||||||||
| getSponsorCustomizedForm, | ||||||||||||||||||||||||||||||||||||||||
| getSponsorManagedForm, | ||||||||||||||||||||||||||||||||||||||||
| upgradeSponsorManagedForm, | ||||||||||||||||||||||||||||||||||||||||
| resetSponsorCustomizedForm, | ||||||||||||||||||||||||||||||||||||||||
| saveSponsorCustomizedForm, | ||||||||||||||||||||||||||||||||||||||||
| updateSponsorCustomizedForm | ||||||||||||||||||||||||||||||||||||||||
|
|
@@ -24,11 +26,14 @@ const CustomizedFormPopup = ({ | |||||||||||||||||||||||||||||||||||||||
| sponsor, | ||||||||||||||||||||||||||||||||||||||||
| summitId, | ||||||||||||||||||||||||||||||||||||||||
| summitTZ, | ||||||||||||||||||||||||||||||||||||||||
| upgradeManaged, | ||||||||||||||||||||||||||||||||||||||||
| open, | ||||||||||||||||||||||||||||||||||||||||
| onClose, | ||||||||||||||||||||||||||||||||||||||||
| onSaved, | ||||||||||||||||||||||||||||||||||||||||
| getSponsorCustomizedForm, | ||||||||||||||||||||||||||||||||||||||||
| getSponsorManagedForm, | ||||||||||||||||||||||||||||||||||||||||
| resetSponsorCustomizedForm, | ||||||||||||||||||||||||||||||||||||||||
| upgradeSponsorManagedForm, | ||||||||||||||||||||||||||||||||||||||||
| saveSponsorCustomizedForm, | ||||||||||||||||||||||||||||||||||||||||
| updateSponsorCustomizedForm | ||||||||||||||||||||||||||||||||||||||||
| }) => { | ||||||||||||||||||||||||||||||||||||||||
|
|
@@ -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); | ||||||||||||||||||||||||||||||||||||||||
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing The effect uses 🔧 Proposed fix useEffect(() => {
if (formId) {
if (upgradeManaged) {
getSponsorManagedForm(formId);
} else {
getSponsorCustomizedForm(formId);
}
}
- }, [formId]);
+ }, [formId, upgradeManaged]);📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
|
|
@@ -125,6 +136,8 @@ const mapStateToProps = ({ | |||||||||||||||||||||||||||||||||||||||
| export default connect(mapStateToProps, { | ||||||||||||||||||||||||||||||||||||||||
| resetSponsorCustomizedForm, | ||||||||||||||||||||||||||||||||||||||||
| getSponsorCustomizedForm, | ||||||||||||||||||||||||||||||||||||||||
| getSponsorManagedForm, | ||||||||||||||||||||||||||||||||||||||||
| upgradeSponsorManagedForm, | ||||||||||||||||||||||||||||||||||||||||
| saveSponsorCustomizedForm, | ||||||||||||||||||||||||||||||||||||||||
| updateSponsorCustomizedForm | ||||||||||||||||||||||||||||||||||||||||
| })(CustomizedFormPopup); | ||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.