Skip to content
This repository has been archived by the owner on Feb 9, 2022. It is now read-only.

Commit

Permalink
Fixed attendee extra question by ticket type
Browse files Browse the repository at this point in the history
* show extra questions availables when all tickets are deactivated
  • Loading branch information
smarcet committed Jul 12, 2023
1 parent ac885f4 commit a568324
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 6 deletions.
15 changes: 12 additions & 3 deletions src/actions/attendee-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,14 @@ export const getAttendeeOrders = ( attendee ) => async (dispatch) => {
);
};

export const getAllowedExtraQuestions = ( attendeeId ) => async (dispatch, getState) => {
/**
*
* @param attendeeId
* @param tickets_exclude_inactives
* @returns {function(*, *): Promise<*>}
*/
export const getAllowedExtraQuestions = ( attendeeId, tickets_exclude_inactives = true ) => async (dispatch, getState) => {

const { currentSummitState } = getState();
const accessToken = await getAccessTokenSafely();
const { currentSummit } = currentSummitState;
Expand All @@ -291,16 +298,18 @@ export const getAllowedExtraQuestions = ( attendeeId ) => async (dispatch, getSt
expand : '*sub_question_rules,*sub_question,*values',
page : 1,
per_page : 100,
access_token : accessToken
access_token : accessToken,
'filter[]' : 'tickets_exclude_inactives=='+(tickets_exclude_inactives? 'true' : 'false'),
};

return getRequest(
null,
createAction(RECEIVE_ALLOWED_EXTRA_QUESTIONS),
`${window.API_BASE_URL}/api/v1/summits/${currentSummit.id}/attendees/${attendeeId}/allowed-extra-questions`,
authErrorHandler
)(params)(dispatch).then(() => {
)(params)(dispatch).then((payload) => {
dispatch(stopLoading());
return payload;
}
);
};
Expand Down
1 change: 1 addition & 0 deletions src/components/forms/attendee-form/attendee-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ class AttendeeForm extends React.Component {
title={T.translate("edit_attendee.extra_questions")}
handleClick={this.toggleSection.bind(this, 'extra_questions')}>
<ExtraQuestionsForm
readOnly={this.props.ExtraQuestionsFormReadOnly}
extraQuestions={entity.allowed_extra_questions}
userAnswers={entity.extra_questions}
onAnswerChanges={this.handleSubmit}
Expand Down
39 changes: 36 additions & 3 deletions src/pages/attendees/edit-summit-attendee-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class EditSummitAttendeePage extends React.Component {
constructor(props) {
super(props);
this.handleOnSubmit = this.handleOnSubmit.bind(this);
this.state = {
ExtraQuestionsFormReadOnly : false,
}
}

componentDidMount() {
Expand All @@ -34,8 +37,19 @@ class EditSummitAttendeePage extends React.Component {
if(!new_attendee_id) {
this.props.resetAttendeeForm();
} else {
this.setState({...this.state, ExtraQuestionsFormReadOnly:false});
this.props.getAttendee(new_attendee_id).then(() => {
this.props.getAllowedExtraQuestions(new_attendee_id);
this.props.getAllowedExtraQuestions(new_attendee_id).then((payload) => {
console.log(payload);
if(!payload.total){
// we dont have any available extra questions, check if we have some related to
// deactivated tickets
this.props.getAllowedExtraQuestions(new_attendee_id, false);
// and mark extra question form as read only
this.setState({...this.state, ExtraQuestionsFormReadOnly:true});
}

});
});
}
}
Expand All @@ -48,16 +62,34 @@ class EditSummitAttendeePage extends React.Component {
if (!newId) {
this.props.resetAttendeeForm();
} else {
this.setState({...this.state, ExtraQuestionsFormReadOnly:false});
this.props.getAttendee(newId).then(() => {
this.props.getAllowedExtraQuestions(newId);
this.props.getAllowedExtraQuestions(newId).then((payload) =>{
if(!payload.total){
// we dont have any available extra questions, check if we have some related to
// deactivated tickets
this.props.getAllowedExtraQuestions(newId, false);
// and mark extra question form as read only
this.setState({...this.state, ExtraQuestionsFormReadOnly:true});
}
});
});
}
}
}

handleOnSubmit(entity){
let {saveAttendee, getAllowedExtraQuestions} = this.props;
saveAttendee(entity).then(() => getAllowedExtraQuestions(entity.id));
this.setState({...this.state, ExtraQuestionsFormReadOnly:false});
saveAttendee(entity).then(() => getAllowedExtraQuestions(entity.id).then((payload) => {
if(!payload.total){
// we dont have any available extra questions, check if we have some related to
// deactivated tickets
this.props.getAllowedExtraQuestions(entity.id, false);
// and mark extra question form as read only
this.setState({...this.state, ExtraQuestionsFormReadOnly:true});
}
}));
}

render(){
Expand All @@ -81,6 +113,7 @@ class EditSummitAttendeePage extends React.Component {
onSaveTicket={this.props.saveTicket}
onDeleteTicket={this.props.deleteTicket}
onDeleteRsvp={this.props.deleteRsvp}
ExtraQuestionsFormReadOnly={this.state.ExtraQuestionsFormReadOnly}
/>
}
</div>
Expand Down

0 comments on commit a568324

Please sign in to comment.