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
83 changes: 47 additions & 36 deletions src/actions/sponsor-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -611,48 +611,54 @@ export const saveSponsor = (entity) => async (dispatch, getState) => {
const { currentSummit } = currentSummitState;

const params = {
access_token: accessToken
access_token: accessToken,
expand:
"company,members,sponsorships,sponsorships.type,sponsorships.type.type,featured_event,extra_questions,extra_questions.values,lead_report_setting",
fields:
"featured_event.id,featured_event.title,sponsorships.id,sponsorships.type.id,sponsorships.type.type.id,sponsorships.type.type.name"
};

dispatch(startLoading());

const normalizedEntity = normalizeSponsor(entity);

if (entity.id) {
putRequest(
return putRequest(
createAction(UPDATE_SPONSOR),
createAction(SPONSOR_UPDATED),
`${window.API_BASE_URL}/api/v1/summits/${currentSummit.id}/sponsors/${entity.id}`,
normalizedEntity,
authErrorHandler,
snackbarErrorHandler,
entity
)(params)(dispatch).then(() => {
dispatch(showSuccessMessage(T.translate("edit_sponsor.sponsor_saved")));
});
} else {
const success_message = {
title: T.translate("general.done"),
html: T.translate("edit_sponsor.sponsor_created"),
type: "success"
};
)(params)(dispatch)
.then(() => {
dispatch(
snackbarSuccessHandler({
title: T.translate("general.success"),
html: T.translate("edit_sponsor.sponsor_saved")
})
);
})
.finally(() => dispatch(stopLoading()));
}

postRequest(
createAction(UPDATE_SPONSOR),
createAction(SPONSOR_ADDED),
`${window.API_BASE_URL}/api/v1/summits/${currentSummit.id}/sponsors`,
normalizedEntity,
authErrorHandler,
entity
)(params)(dispatch).then((payload) => {
return postRequest(
createAction(UPDATE_SPONSOR),
createAction(SPONSOR_ADDED),
`${window.API_BASE_URL}/api/v1/summits/${currentSummit.id}/sponsors`,
normalizedEntity,
snackbarErrorHandler,
entity
)(params)(dispatch)
.then(() => {
dispatch(
showMessage(success_message, () => {
history.push(
`/app/summits/${currentSummit.id}/sponsors/${payload.response.id}`
);
snackbarSuccessHandler({
title: T.translate("general.success"),
html: T.translate("edit_sponsor.sponsor_created")
})
);
});
}
})
.finally(() => dispatch(stopLoading()));
};

export const addMemberToSponsor =
Expand Down Expand Up @@ -746,16 +752,21 @@ export const updateSponsorOrder =
const normalizeSponsor = (entity) => {
const normalizedEntity = { ...entity };

normalizedEntity.company_id = normalizedEntity.company?.id || 0;
normalizedEntity.sponsorship_id = normalizedEntity.sponsorship?.id || 0;
normalizedEntity.featured_event_id =
normalizedEntity.featured_event && normalizedEntity.featured_event.id
? normalizedEntity.featured_event.id
: 0;

delete normalizedEntity.featured_event;
delete normalizedEntity.company;
delete normalizedEntity.sponsorship;
if (normalizedEntity.hasOwnProperty("company")) {
normalizedEntity.company_id = normalizedEntity.company?.id || 0;
delete normalizedEntity.company;
}

if (normalizedEntity.hasOwnProperty("sponsorship")) {
normalizedEntity.sponsorship_id = normalizedEntity.sponsorship?.id || 0;
delete normalizedEntity.sponsorship;
}

if (normalizedEntity.hasOwnProperty("featured_event")) {
normalizedEntity.featured_event_id =
normalizedEntity.featured_event?.id || 0;
delete normalizedEntity.featured_event;
}

return normalizedEntity;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
removeTierFromSponsor,
resetSponsorExtraQuestionForm,
saveAddonsToSponsorship,
saveSponsor,
saveSponsorExtraQuestion,
saveSponsorExtraQuestionValue,
setSelectedSponsorship,
Expand All @@ -52,15 +53,16 @@ const SponsorGeneralForm = ({
saveSponsorExtraQuestionValue,
resetSponsorExtraQuestionForm,
deleteExtraQuestion,
updateExtraQuestionOrder
updateExtraQuestionOrder,
saveSponsor
}) => {
const handleSponsorshipPaginate = (page, perPage, order, orderDir) => {
getSponsorSponsorships(sponsor.id, page, perPage, order, orderDir);
};

return (
<Box sx={{ mt: 2 }}>
<SponsorHeader sponsor={sponsor} />
<SponsorHeader sponsor={sponsor} onSave={saveSponsor} />
<Sponsorship
sponsor={sponsor}
summitId={currentSummit.id}
Expand Down Expand Up @@ -117,5 +119,6 @@ export default connect(mapStateToProps, {
saveSponsorExtraQuestionValue,
resetSponsorExtraQuestionForm,
deleteExtraQuestion,
updateExtraQuestionOrder
updateExtraQuestionOrder,
saveSponsor
})(SponsorGeneralForm);
Original file line number Diff line number Diff line change
Expand Up @@ -11,82 +11,146 @@
* limitations under the License.
* */

import React from "react";
import React, { useEffect, useState } from "react";
import T from "i18n-react/dist/i18n-react";
import { Box, Divider, Grid2, Typography } from "@mui/material";
import {
Box,
Button,
Checkbox,
Divider,
Grid2,
Typography
} from "@mui/material";

const SponsorHeader = ({ sponsor }) => (
<Box sx={{ px: 2, py: 0, backgroundColor: "#FFF" }}>
<Grid2 container size={12} sx={{ height: "68px", alignItems: "center" }}>
<Grid2 size={12}>
<Typography
sx={{
fontWeight: "500",
letterSpacing: "0.15px",
fontSize: "2rem",
lineHeight: "1.6rem"
}}
>
{T.translate("edit_sponsor.general_information")}
</Typography>
const SponsorHeader = ({ sponsor, onSave }) => {
const [isPublished, setIsPublished] = useState(sponsor.is_published);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
const [isSaving, setIsSaving] = useState(false);

useEffect(() => {
setIsPublished(sponsor.is_published);
}, [sponsor.id, sponsor.is_published]);

const handlePublishSave = () => {
const entity = { id: sponsor.id, is_published: isPublished };
setIsSaving(true);
Promise.resolve(onSave(entity))
.catch(() => {})
.finally(() => setIsSaving(false));
};

return (
<Box sx={{ px: 2, py: 0, backgroundColor: "#FFF" }}>
<Grid2 container size={12} sx={{ height: "68px", alignItems: "center" }}>
<Grid2 size={12}>
<Typography
sx={{
fontWeight: "500",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

lets try not to do this and work with standard tags like h3 or h4

letterSpacing: "0.15px",
fontSize: "2rem",
lineHeight: "1.6rem"
}}
>
{T.translate("edit_sponsor.general_information")}
</Typography>
</Grid2>
</Grid2>
</Grid2>
<Divider />
<Grid2
container
size={12}
sx={{ height: "75px", gap: "10px", alignItems: "center" }}
>
<Grid2 size={3}>
<Typography
sx={{
fontSize: "1.4rem",
lineHeight: "1.57rem",
fontWeight: "500"
}}
>
{T.translate("edit_sponsor.sponsor_name")}
</Typography>
<Divider />
<Grid2
container
size={12}
sx={{ height: "75px", gap: "10px", alignItems: "center" }}
>
<Grid2 size={3}>
<Typography
sx={{
fontSize: "1.4rem",
lineHeight: "1.57rem",
fontWeight: "500"
}}
>
{T.translate("edit_sponsor.sponsor_name")}
</Typography>
</Grid2>
<Grid2>{sponsor.company?.name}</Grid2>
</Grid2>
<Grid2>{sponsor.company?.name}</Grid2>
</Grid2>
<Divider />
<Grid2
container
size={12}
sx={{ height: "75px", gap: "10px", alignItems: "center" }}
>
<Grid2 size={3}>
<Typography
sx={{
fontSize: "1.4rem",
lineHeight: "1.57rem",
fontWeight: "500"
}}
>
{T.translate("edit_sponsor.sponsor_address")}
</Typography>
<Divider />
<Grid2
container
size={12}
sx={{ height: "75px", gap: "10px", alignItems: "center" }}
>
<Grid2 size={3}>
<Typography
sx={{
fontSize: "1.4rem",
lineHeight: "1.57rem",
fontWeight: "500"
}}
>
{T.translate("edit_sponsor.sponsor_address")}
</Typography>
</Grid2>
<Grid2>
{[
sponsor.company?.city,
sponsor.company?.state,
sponsor.company?.country
]
// filter empty or undefined fields
.filter(Boolean)
.join(" - ")}
{sponsor.company?.contact_email && (
<>
&nbsp;
<a href={`mailto:${sponsor.company.contact_email}`}>
{sponsor.company.contact_email}
</a>
</>
)}
</Grid2>
</Grid2>
<Grid2>
{[
sponsor.company?.city,
sponsor.company?.state,
sponsor.company?.country
]
// filter empty or undefined fields
.filter(Boolean)
.join(" - ")}
{sponsor.company?.contact_email && (
<>
&nbsp;
<a href={`mailto:${sponsor.company.contact_email}`}>
{sponsor.company.contact_email}
</a>
</>
)}
<Divider />
<Grid2
container
size={12}
sx={{ height: "75px", gap: "10px", alignItems: "center" }}
>
<Grid2 size={3}>
<Typography
id="sponsor-is-published-label"
sx={{
fontSize: "1.4rem",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

same here

lineHeight: "1.57rem",
fontWeight: "500"
}}
>
{T.translate("edit_sponsor.is_published")}
</Typography>
</Grid2>
<Grid2
container
size="grow"
sx={{ justifyContent: "space-between", alignItems: "center" }}
>
<Checkbox
sx={{ display: "inline-block" }}
checked={isPublished}
disabled={isSaving}
onChange={() => setIsPublished(!isPublished)}
inputProps={{ "aria-labelledby": "sponsor-is-published-label" }}
/>
Comment thread
coderabbitai[bot] marked this conversation as resolved.
<Button
variant="contained"
onClick={handlePublishSave}
disabled={isSaving}
sx={{ height: "36px" }}
>
{T.translate("general.save")}
</Button>
</Grid2>
</Grid2>
</Grid2>
</Box>
);
</Box>
);
};

export default SponsorHeader;
5 changes: 2 additions & 3 deletions src/reducers/sponsors/sponsor-reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,9 @@ const sponsorReducer = (state = DEFAULT_STATE, action) => {
return { ...state, entity: { ...DEFAULT_ENTITY }, errors: {} };

case UPDATE_SPONSOR:
return { ...state, entity: { ...payload }, errors: {} };
return { ...state, entity: { ...state.entity, ...payload }, errors: {} };
case SPONSOR_ADDED:
case SPONSOR_UPDATED:
case RECEIVE_SPONSOR: {
const entity = { ...payload.response };

Expand All @@ -175,8 +176,6 @@ const sponsorReducer = (state = DEFAULT_STATE, action) => {
entity: { ...state.entity, ...entity }
};
}
case SPONSOR_UPDATED:
return state;
case MEMBER_ADDED_TO_SPONSOR: {
const { member } = payload;
return {
Expand Down
Loading