From a305ad08ec722b534d37e6f4c47d007427b85ced Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Castillo?= Date: Fri, 20 Dec 2024 16:52:22 -0300 Subject: [PATCH 1/2] Add ticket type input on promocodes and attendee ticket modal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tomás Castillo --- src/actions/promocode-actions.js | 10 ++- .../forms/attendee-form/ticket-component.js | 64 ++++++++++--------- .../forms/generic-base-pc-form.js | 50 +++++++-------- src/reducers/attendees/attendee-reducer.js | 6 +- .../orders/purchase-order-list-reducer.js | 2 +- 5 files changed, 70 insertions(+), 62 deletions(-) diff --git a/src/actions/promocode-actions.js b/src/actions/promocode-actions.js index e96594224..5e9fcf3e8 100644 --- a/src/actions/promocode-actions.js +++ b/src/actions/promocode-actions.js @@ -147,6 +147,12 @@ const normalizeEntity = (entity) => { normalizedEntity.tags = entity.tags.map((e) => e.tag); } + if (entity.allowed_ticket_types.length > 0) { + normalizedEntity.allowed_ticket_types = entity.allowed_ticket_types.map( + (tt) => tt.id + ); + } + delete normalizedEntity.owner; delete normalizedEntity.owner_id; delete normalizedEntity.speaker; @@ -240,7 +246,7 @@ export const getPromocode = (promocodeId) => async (dispatch, getState) => { const params = { expand: - "owner,sponsor,sponsor.company,sponsor.sponsorship,sponsor.sponsorship.type,speaker,tickets,ticket_type,ticket_types_rules,tags", + "owner,sponsor,sponsor.company,sponsor.sponsorship,sponsor.sponsorship.type,speaker,tickets,ticket_type,ticket_types_rules,tags,allowed_ticket_types", access_token: accessToken }; @@ -270,7 +276,7 @@ export const savePromocode = const params = { expand: - "owner,sponsor,sponsor.company,sponsor.sponsorship,speaker,tickets,ticket_type,ticket_types_rules,tags", + "owner,sponsor,sponsor.company,sponsor.sponsorship,speaker,tickets,ticket_type,ticket_types_rules,tags,allowed_ticket_types", access_token: accessToken }; diff --git a/src/components/forms/attendee-form/ticket-component.js b/src/components/forms/attendee-form/ticket-component.js index ae423284a..4a1f15fa9 100644 --- a/src/components/forms/attendee-form/ticket-component.js +++ b/src/components/forms/attendee-form/ticket-component.js @@ -9,18 +9,19 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - **/ + * */ import React from "react"; -import history from "../../../history"; import T from "i18n-react/dist/i18n-react"; import Swal from "sweetalert2"; import { Modal } from "react-bootstrap"; import { MemberInput, - Dropdown + TicketTypesInput } from "openstack-uicore-foundation/lib/components"; +import history from "../../../history"; + export default class TicketComponent extends React.Component { constructor(props) { super(props); @@ -51,15 +52,15 @@ export default class TicketComponent extends React.Component { } onDelete(ticket_id, ev) { - let { onDelete, attendeeId } = this.props; + const { onDelete, attendeeId } = this.props; ev.preventDefault(); - let msg = { + const msg = { title: T.translate("general.are_you_sure"), text: T.translate("edit_attendee.remove_ticket_from_attendee"), type: "warning" }; - Swal.fire(msg).then(function () { + Swal.fire(msg).then(() => { onDelete(attendeeId, ticket_id); }); } @@ -69,7 +70,7 @@ export default class TicketComponent extends React.Component { this.setState({ showAddModal: true }); } - onCloseModal(ev) { + onCloseModal() { this.setState({ showEditModal: false, showAddModal: false }); } @@ -79,10 +80,10 @@ export default class TicketComponent extends React.Component { }); } - handleTicketReassign(ev) { - let { onReassign, attendeeId } = this.props; - let newOwner = { ...this.state.newOwner }; - let editTicket = { ...this.state.editTicket }; + handleTicketReassign() { + const { onReassign, attendeeId } = this.props; + const newOwner = { ...this.state.newOwner }; + const editTicket = { ...this.state.editTicket }; this.setState({ showEditModal: false, @@ -93,9 +94,13 @@ export default class TicketComponent extends React.Component { onReassign(attendeeId, newOwner.id, editTicket.id); } - handleTicketSave(ev) { - let { onSave, attendeeId } = this.props; - let newTicket = { ...this.state.newTicket }; + handleTicketSave() { + const { onSave, attendeeId } = this.props; + const newTicket = { ...this.state.newTicket }; + + newTicket.ticket_type_id = newTicket.ticket_type_id.id; + + console.log("CHECK...", newTicket); this.setState({ showAddModal: false, @@ -110,11 +115,11 @@ export default class TicketComponent extends React.Component { } handleTicketChange(ev) { - let newTicket = { ...this.state.newTicket }; - let { value, id } = ev.target; + const newTicket = { ...this.state.newTicket }; + const { value, id } = ev.target; newTicket[id] = value; - this.setState({ newTicket: newTicket }); + this.setState({ newTicket }); } handleTicketLink = (ev, ticket) => { @@ -126,12 +131,8 @@ export default class TicketComponent extends React.Component { }; render() { - let { tickets, summit } = this.props; - let { showEditModal, showAddModal, editTicket, newTicket } = this.state; - - let ticket_types_ddl = summit.ticket_types.map((t) => { - return { label: t.name, value: t.id }; - }); + const { tickets, summit } = this.props; + const { showEditModal, showAddModal, editTicket, newTicket } = this.state; return (
@@ -149,7 +150,7 @@ export default class TicketComponent extends React.Component { {tickets.map((t) => (
{ - return member.hasOwnProperty("email") + getOptionLabel={(member) => + member.hasOwnProperty("email") ? `${member.first_name} ${member.last_name} (${member.email})` - : `${member.first_name} ${member.last_name} (${member.id})`; - }} + : `${member.first_name} ${member.last_name} (${member.id})` + } value={this.state.newOwner} onChange={this.handleMemberChange} /> @@ -301,14 +302,17 @@ export default class TicketComponent extends React.Component { } > -
{summit.external_registration_feed_type === "none" && ( diff --git a/src/components/forms/promocode-form/forms/generic-base-pc-form.js b/src/components/forms/promocode-form/forms/generic-base-pc-form.js index 819d9e297..6d349ed98 100644 --- a/src/components/forms/promocode-form/forms/generic-base-pc-form.js +++ b/src/components/forms/promocode-form/forms/generic-base-pc-form.js @@ -1,34 +1,30 @@ import React from "react"; import T from "i18n-react"; +import { TicketTypesInput } from "openstack-uicore-foundation/lib/components"; import BasePCForm from "./base-pc-form"; -import { Dropdown } from "openstack-uicore-foundation/lib/components"; -const GenericBasePCForm = (props) => { - let ticket_types_ddl = props.summit.ticket_types.map((f) => ({ - label: f.name, - value: f.id - })); - - return ( - <> - -
-
- - -
+const GenericBasePCForm = (props) => ( + <> + +
+
+ +
- - ); -}; +
+ +); export default GenericBasePCForm; diff --git a/src/reducers/attendees/attendee-reducer.js b/src/reducers/attendees/attendee-reducer.js index 3e57fea94..c3f63c9b1 100644 --- a/src/reducers/attendees/attendee-reducer.js +++ b/src/reducers/attendees/attendee-reducer.js @@ -95,12 +95,14 @@ const attendeeReducer = (state = DEFAULT_STATE, action = {}) => { return { ...state }; } case TICKET_ADDED: { - const newTicket = payload.response; + const newOrder = payload.response; + const newTicket = newOrder.tickets[0]; return { ...state, entity: { ...state.entity, - tickets: [...state.entity.tickets, newTicket] + tickets: [...state.entity.tickets, newTicket], + orders: [...state.entity.orders, newOrder] } }; } diff --git a/src/reducers/orders/purchase-order-list-reducer.js b/src/reducers/orders/purchase-order-list-reducer.js index d8fd98249..55f165769 100644 --- a/src/reducers/orders/purchase-order-list-reducer.js +++ b/src/reducers/orders/purchase-order-list-reducer.js @@ -23,7 +23,7 @@ import { import { SET_CURRENT_SUMMIT } from "../../actions/summit-actions"; const DEFAULT_STATE = { - purchaseOrders: {}, + purchaseOrders: [], term: null, order: "created", orderDir: 1, From 863c56cc01863e84dbe55eec893c6d11ea652987 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Castillo?= Date: Mon, 23 Dec 2024 17:25:09 -0300 Subject: [PATCH 2/2] clean console logs, move logic from action to form MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tomás Castillo --- src/actions/promocode-actions.js | 6 ------ src/components/forms/attendee-form/ticket-component.js | 2 -- src/components/forms/promocode-form/index.js | 8 ++++++++ src/reducers/attendees/attendee-reducer.js | 6 ++---- src/reducers/orders/purchase-order-list-reducer.js | 2 +- 5 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/actions/promocode-actions.js b/src/actions/promocode-actions.js index 5e9fcf3e8..dd48fecf3 100644 --- a/src/actions/promocode-actions.js +++ b/src/actions/promocode-actions.js @@ -147,12 +147,6 @@ const normalizeEntity = (entity) => { normalizedEntity.tags = entity.tags.map((e) => e.tag); } - if (entity.allowed_ticket_types.length > 0) { - normalizedEntity.allowed_ticket_types = entity.allowed_ticket_types.map( - (tt) => tt.id - ); - } - delete normalizedEntity.owner; delete normalizedEntity.owner_id; delete normalizedEntity.speaker; diff --git a/src/components/forms/attendee-form/ticket-component.js b/src/components/forms/attendee-form/ticket-component.js index 4a1f15fa9..c957db68b 100644 --- a/src/components/forms/attendee-form/ticket-component.js +++ b/src/components/forms/attendee-form/ticket-component.js @@ -100,8 +100,6 @@ export default class TicketComponent extends React.Component { newTicket.ticket_type_id = newTicket.ticket_type_id.id; - console.log("CHECK...", newTicket); - this.setState({ showAddModal: false, newTicket: { diff --git a/src/components/forms/promocode-form/index.js b/src/components/forms/promocode-form/index.js index e8c3ca93f..9b820e6b7 100644 --- a/src/components/forms/promocode-form/index.js +++ b/src/components/forms/promocode-form/index.js @@ -137,6 +137,12 @@ class PromocodeForm extends React.Component { const { entity } = this.state; const typeScope = this.fragmentParser.getParam("type"); + if (entity.allowed_ticket_types.length > 0) { + entity.allowed_ticket_types = entity.allowed_ticket_types.map( + (tt) => tt.id + ); + } + if (this.validate()) { onSubmit(entity, typeScope === "sponsor"); } @@ -211,6 +217,8 @@ class PromocodeForm extends React.Component { } = this.props; const typeScope = this.fragmentParser.getParam("type"); + console.log("CHECKING...", entity); + let promocode_class_ddl = allClasses.map((c) => ({ label: c.class_name, value: c.class_name diff --git a/src/reducers/attendees/attendee-reducer.js b/src/reducers/attendees/attendee-reducer.js index c3f63c9b1..3e57fea94 100644 --- a/src/reducers/attendees/attendee-reducer.js +++ b/src/reducers/attendees/attendee-reducer.js @@ -95,14 +95,12 @@ const attendeeReducer = (state = DEFAULT_STATE, action = {}) => { return { ...state }; } case TICKET_ADDED: { - const newOrder = payload.response; - const newTicket = newOrder.tickets[0]; + const newTicket = payload.response; return { ...state, entity: { ...state.entity, - tickets: [...state.entity.tickets, newTicket], - orders: [...state.entity.orders, newOrder] + tickets: [...state.entity.tickets, newTicket] } }; } diff --git a/src/reducers/orders/purchase-order-list-reducer.js b/src/reducers/orders/purchase-order-list-reducer.js index 55f165769..d8fd98249 100644 --- a/src/reducers/orders/purchase-order-list-reducer.js +++ b/src/reducers/orders/purchase-order-list-reducer.js @@ -23,7 +23,7 @@ import { import { SET_CURRENT_SUMMIT } from "../../actions/summit-actions"; const DEFAULT_STATE = { - purchaseOrders: [], + purchaseOrders: {}, term: null, order: "created", orderDir: 1,