Skip to content

Commit

Permalink
replace ddl on event type page
Browse files Browse the repository at this point in the history
Signed-off-by: Tomás Castillo <[email protected]>
  • Loading branch information
tomrndom committed Nov 13, 2024
1 parent 2aaf6b7 commit 936f810
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 42 deletions.
54 changes: 31 additions & 23 deletions src/actions/event-type-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
* 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 T from "i18n-react/dist/i18n-react";
import history from "../history";
import {
getRequest,
putRequest,
Expand All @@ -24,6 +23,7 @@ import {
showSuccessMessage,
authErrorHandler
} from "openstack-uicore-foundation/lib/utils/actions";
import history from "../history";
import { getAccessTokenSafely } from "../utils/methods";

export const REQUEST_EVENT_TYPES = "REQUEST_EVENT_TYPES";
Expand Down Expand Up @@ -67,7 +67,9 @@ export const getEventType = (eventTypeId) => async (dispatch, getState) => {
dispatch(startLoading());

const params = {
expand: "allowed_media_upload_types, allowed_media_upload_types.type",
expand:
"allowed_media_upload_types, allowed_media_upload_types.type, allowed_ticket_types",
fields: "allowed_ticket_types.id,allowed_ticket_types.name",
access_token: accessToken
};

Expand All @@ -81,7 +83,7 @@ export const getEventType = (eventTypeId) => async (dispatch, getState) => {
});
};

export const resetEventTypeForm = () => (dispatch, getState) => {
export const resetEventTypeForm = () => (dispatch) => {
dispatch(createAction(RESET_EVENT_TYPE_FORM)({}));
};

Expand All @@ -103,7 +105,7 @@ export const saveEventType = (entity) => async (dispatch, getState) => {
normalizedEntity,
authErrorHandler,
entity
)(params)(dispatch).then((payload) => {
)(params)(dispatch).then(() => {
dispatch(
showSuccessMessage(T.translate("edit_event_type.event_type_saved"))
);
Expand Down Expand Up @@ -177,32 +179,38 @@ export const seedEventTypes = () => async (dispatch, getState) => {
const normalizeEntity = (entity) => {
const normalizedEntity = { ...entity };

//remove # from color hexa
normalizedEntity["color"] = normalizedEntity["color"].substr(1);
// remove # from color hexa
normalizedEntity.color = normalizedEntity.color.substr(1);

delete normalizedEntity["id"];
delete normalizedEntity["created"];
delete normalizedEntity["last_edited"];
delete normalizedEntity["is_default"];
delete normalizedEntity.id;
delete normalizedEntity.created;
delete normalizedEntity.last_edited;
delete normalizedEntity.is_default;

if (normalizedEntity.class_name === "EVENT_TYPE") {
delete normalizedEntity["should_be_available_on_cfp"];
delete normalizedEntity["use_speakers"];
delete normalizedEntity["are_speakers_mandatory"];
delete normalizedEntity["min_speakers"];
delete normalizedEntity["max_speakers"];
delete normalizedEntity["use_moderator"];
delete normalizedEntity["is_moderator_mandatory"];
delete normalizedEntity["min_moderators"];
delete normalizedEntity["max_moderators"];
delete normalizedEntity["moderator_label"];
delete normalizedEntity["min_duration"];
delete normalizedEntity["max_duration"];
delete normalizedEntity.should_be_available_on_cfp;
delete normalizedEntity.use_speakers;
delete normalizedEntity.are_speakers_mandatory;
delete normalizedEntity.min_speakers;
delete normalizedEntity.max_speakers;
delete normalizedEntity.use_moderator;
delete normalizedEntity.is_moderator_mandatory;
delete normalizedEntity.min_moderators;
delete normalizedEntity.max_moderators;
delete normalizedEntity.moderator_label;
delete normalizedEntity.min_duration;
delete normalizedEntity.max_duration;
}

if (normalizedEntity.show_always_on_schedule) {
normalizedEntity.allowed_ticket_types = [];
}

if (normalizedEntity.allowed_ticket_types.length > 0) {
normalizedEntity.allowed_ticket_types = entity.allowed_ticket_types.map(
(tt) => (tt.hasOwnProperty("id") ? tt.id : tt)
);
}

return normalizedEntity;
};
37 changes: 18 additions & 19 deletions src/components/forms/event-type-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* 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 T from "i18n-react/dist/i18n-react";
Expand All @@ -18,7 +18,8 @@ import {
Dropdown,
Input,
SimpleLinkList,
Panel
Panel,
TicketTypesInput
} from "openstack-uicore-foundation/lib/components";
import {
isEmpty,
Expand All @@ -44,7 +45,7 @@ class EventTypeForm extends React.Component {
this.handleMediaUploadLink = this.handleMediaUploadLink.bind(this);
}

componentDidUpdate(prevProps, prevState, snapshot) {
componentDidUpdate(prevProps) {
const state = {};
scrollToError(this.props.errors);

Expand All @@ -63,8 +64,8 @@ class EventTypeForm extends React.Component {
}

handleChange(ev) {
const entity = { ...this.state.entity };
const errors = { ...this.state.errors };
const newEntity = { ...this.state.entity };
const newErrors = { ...this.state.errors };
let { value, id } = ev.target;

if (ev.target.type === "checkbox") {
Expand All @@ -75,22 +76,22 @@ class EventTypeForm extends React.Component {
value = parseInt(ev.target.value);
}

errors[id] = "";
entity[id] = value;
this.setState({ entity: entity, errors: errors });
newErrors[id] = "";
newEntity[id] = value;
this.setState({ entity: newEntity, errors: newErrors });
}

handleShowAlwaysChange(ev) {
const entity = { ...this.state.entity };
const newEntity = { ...this.state.entity };
const value = ev.target.checked;

// if true then we clear allowed ticket types
if (value) {
entity.allowed_ticket_types = [];
newEntity.allowed_ticket_types = [];
}

entity.show_always_on_schedule = value;
this.setState({ entity: entity });
newEntity.show_always_on_schedule = value;
this.setState({ entity: newEntity });
}

handleSubmit(ev) {
Expand Down Expand Up @@ -124,10 +125,6 @@ class EventTypeForm extends React.Component {
{ label: "Presentation", value: "PRESENTATION_TYPE" },
{ label: "Event", value: "EVENT_TYPE" }
];
const ticket_types_ddl = currentSummit.ticket_types.map((t) => ({
value: t.id,
label: t.name
}));

const blackout_times_ddl = [
{
Expand Down Expand Up @@ -598,15 +595,17 @@ class EventTypeForm extends React.Component {
{" "}
{T.translate("edit_event_type.allowed_ticket_types")}
</label>
<Dropdown
<TicketTypesInput
id="allowed_ticket_types"
value={entity.allowed_ticket_types}
value={entity?.allowed_ticket_types}
placeholder={T.translate(
"edit_event_type.placeholders.allowed_ticket_types"
)}
options={ticket_types_ddl}
summitId={currentSummit.id}
onChange={this.handleChange}
optionsLimit={100}
disabled={!!entity.show_always_on_schedule}
defaultOptions
isMulti
/>
</div>
Expand Down

0 comments on commit 936f810

Please sign in to comment.