Skip to content
Closed
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
61 changes: 61 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,37 @@ 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);

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,
Expand All @@ -629,6 +663,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());
});
};

/* ************************************************************************ */
/* CUSTOMIZED FORMS */
/* ************************************************************************ */
Expand Down Expand Up @@ -891,6 +950,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]);

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