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
9 changes: 5 additions & 4 deletions src/actions/sponsor-cart-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,11 @@ export const getSponsorFormsForCart =
orderDir = DEFAULT_ORDER_DIR
) =>
async (dispatch, getState) => {
const { currentSummitState } = getState();
const { currentSummitState, currentSponsorState } = getState();
const { currentSummit } = currentSummitState;
const { entity: sponsor } = currentSponsorState;
const accessToken = await getAccessTokenSafely();
const filter = ["has_items==1"];
const filter = [];

dispatch(startLoading());

Expand All @@ -215,7 +216,7 @@ export const getSponsorFormsForCart =

const params = {
page: currentPage,
fields: "id,code,name,items",
fields: "id,code,name,items_count",
per_page: DEFAULT_PER_PAGE,
access_token: accessToken
};
Expand All @@ -233,7 +234,7 @@ export const getSponsorFormsForCart =
return getRequest(
createAction(REQUEST_CART_AVAILABLE_FORMS),
createAction(RECEIVE_CART_AVAILABLE_FORMS),
`${window.PURCHASES_API_URL}/api/v1/summits/${currentSummit.id}/show-forms`,
`${window.PURCHASES_API_URL}/api/v1/summits/${currentSummit.id}/sponsors/${sponsor.id}/available-forms`,
authErrorHandler,
{ term, order, orderDir, currentPage }
)(params)(dispatch).then(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/actions/sponsor-forms-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ export const getSponsorCustomizedForm =

const params = {
fields:
"id,code,name,is_archived,opens_at,instructions,expires_at,items_count,allowed_add_ons,meta_fields",
"id,code,name,is_archived,opens_at,instructions,expires_at,items_count,allowed_add_ons,meta_fields,apply_to_all_add_ons",
expand: "allowed_add_ons,meta_fields,meta_fields.values",
access_token: accessToken
};
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2449,7 +2449,8 @@
"add_form_using_template": "Add Form Using Template",
"add_selected_form_template": "Add Selected Form Template",
"customized_form": {
"title": "Create New Form",
"new_form_title": "Create New Form",
"edit_form_title": "Edit Form",
"code": "Code",
"name": "Name",
"addons": "Add-ons",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,8 @@ const buildInitialValues = (form, timeZone) => {

const buildValidationSchema = (items) => {
const schema = items.reduce((acc, item) => {
item.meta_fields.map((f) => {
acc[`i-${item.form_item_id}-c-${f.class_field}-f-${f.type_id}`] =
getYupValidation(f);
});
const quantityKey = `i-${item.form_item_id}-c-global-f-quantity`;

// notes
acc[`i-${item.form_item_id}-c-global-f-notes`] = yup.string(
T.translate("validation.string")
Expand All @@ -181,12 +179,22 @@ const buildValidationSchema = (items) => {
globalQtySchema = globalQtySchema.required(
T.translate("validation.required")
);
acc[`i-${item.form_item_id}-c-global-f-quantity`] = globalQtySchema;
acc[quantityKey] = globalQtySchema;
// custom rate
acc[`i-${item.form_item_id}-c-global-f-custom_rate`] = yup.number(
T.translate("validation.number")
);

item.meta_fields.map((f) => {
acc[`i-${item.form_item_id}-c-${f.class_field}-f-${f.type_id}`] = yup
.mixed()
.when(quantityKey, {
is: (val) => val > 0,
then: () => getYupValidation(f),
otherwise: () => yup.mixed().notRequired()
});
});

return acc;
}, {});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,19 @@ const mockForms = [
id: 1,
code: "FORM001",
name: "Installation Form",
item_count: 5
items_count: 5
},
{
id: 2,
code: "FORM002",
name: "Dismantle Form",
item_count: 3
items_count: 3
},
{
id: 3,
code: "FORM003",
name: "Setup Form",
item_count: 8
items_count: 8
}
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const SelectFormDialog = ({
sortable: true
},
{
columnKey: "item_count",
columnKey: "items_count",
header: T.translate("general.items"),
sortable: false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ const CustomizedFormPopup = ({
component="div"
>
<Typography variant="h5">
{T.translate("edit_sponsor.forms_tab.customized_form.title")}
{T.translate(
`edit_sponsor.forms_tab.customized_form.${
formId ? "edit_form_title" : "new_form_title"
}`
)}
</Typography>
<IconButton
size="large"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ const buildInitialValues = (data, summitTZ) => {
? epochToMomentTimeZone(expires_at, summitTZ)
: null;

normalized.allowed_add_ons = data.apply_to_all_add_ons
? ["all"]
: data.allowed_add_ons;

return normalized;
};

Expand Down
9 changes: 1 addition & 8 deletions src/reducers/sponsors/sponsor-page-cart-list-reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@ const DEFAULT_STATE = {
cartOwner: null
};

const mapForm = (formData) => ({
...formData,
item_count: `${formData.items.length} items`
});

const sponsorPageCartListReducer = (state = DEFAULT_STATE, action) => {
const { type, payload } = action;

Expand Down Expand Up @@ -164,9 +159,7 @@ const sponsorPageCartListReducer = (state = DEFAULT_STATE, action) => {
} = payload.response;

const forms =
currentPage === 1
? data.map(mapForm)
: [...state.availableForms.forms, ...data.map(mapForm)];
currentPage === 1 ? data : [...state.availableForms.forms, ...data];

const availableForms = {
...state.availableForms,
Expand Down
Loading