Skip to content

Commit

Permalink
Fix a problem when you publish an event (#103)
Browse files Browse the repository at this point in the history
* Fix a problem when you publish an event

* Fix style
  • Loading branch information
amieiro authored Feb 19, 2024
1 parent 7c90a06 commit ef9cce1
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions assets/js/translation-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
'click',
function ( e ) {
e.preventDefault();
handleSubmit();
let eventStatus = $( this ).data( 'event-status' );
handleSubmit( eventStatus );
}
);

Expand All @@ -28,19 +29,18 @@
}
);

function handleSubmit() {
function handleSubmit( eventStatus ) {
if ( $( '#event-end' ).val() <= $( '#event-start' ).val() ) {
$gp.notices.error( 'Event end date and time must be later than event start date and time.' );
return;
}
const btnClicked = $( this ).data( 'event-status' );
if ( btnClicked === 'publish' && '' === $( '#event-id' ).val() ) {
if ( eventStatus === 'publish' && '' === $( '#event-id' ).val() ) {
const submitPrompt = 'Are you sure you want to publish this event?';
if ( ! confirm( submitPrompt ) ) {
return;
}
}
$( '#event-form-action' ).val( btnClicked );
$( '#event-form-action' ).val( eventStatus );
const $form = $( '.translation-event-form' );
const $is_creation = $( '#form-name' ).val() === 'create_event';

Expand All @@ -55,11 +55,11 @@
$( '#form-name' ).val( 'edit_event' );
$( '.event-page-title' ).text( 'Edit Event' );
$( '#event-id' ).val( response.data.eventId );
if ( btnClicked === 'publish' ) {
if ( eventStatus === 'publish' ) {
$( 'button[data-event-status="draft"]' ).hide();
$( 'button[data-event-status="publish"]' ).text( 'Update Event' );
}
if ( btnClicked === 'draft' ) {
if ( eventStatus === 'draft' ) {
$( 'button[data-event-status="draft"]' ).text( 'Update Draft' );
}
$( '#event-url' ).removeClass( 'hide-event-url' ).find( 'a' ).attr( 'href', response.data.eventUrl ).text( response.data.eventUrl );
Expand Down

0 comments on commit ef9cce1

Please sign in to comment.