Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.x] Add submitting state for confirmation modal to better visualise a running action #10699

Merged
merged 16 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
7 changes: 6 additions & 1 deletion resources/js/components/assets/Browser/CreateFolder.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<confirmation-modal
name="folder-editor"
:title="modalTitle"
:submitting="submitting"
@cancel="cancel"
@confirm="submit"
>
Expand Down Expand Up @@ -42,6 +43,7 @@ export default {
buttonText: __('Create'),
directory: this.initialDirectory,
errors: {},
submitting: false,
}
},

Expand All @@ -59,11 +61,15 @@ export default {
title: this.title
};

this.submitting = true;

this.$axios.post(url, payload).then(response => {
this.$toast.success(__('Folder created'));
this.$emit('created', response.data);
}).catch(e => {
this.handleErrors(e);
}).finally(() => {
this.submitting = false;
});
},

Expand All @@ -81,7 +87,6 @@ export default {
},

created() {
this.$keys.bindGlobal('enter', this.submit)
this.$keys.bindGlobal('esc', this.cancel)
},

Expand Down
6 changes: 6 additions & 0 deletions resources/js/components/blueprints/BlueprintResetter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
:bodyText="modalBody"
:buttonText="__('Reset')"
:danger="true"
:submitting="submitting"
@confirm="confirmed"
@cancel="cancel"
>
Expand Down Expand Up @@ -36,6 +37,7 @@ export default {
return {
resetting: false,
redirectFromServer: null,
submitting: false,
}
},

Expand Down Expand Up @@ -69,13 +71,16 @@ export default {
},

confirmed() {
this.submitting = true;

this.$axios.delete(this.resetUrl)
.then(response => {
this.redirectFromServer = data_get(response, 'data.redirect');
this.success();
})
.catch(() => {
this.$toast.error(__('Something went wrong'));
this.submitting = false;
});
},

Expand All @@ -92,6 +97,7 @@ export default {

this.$toast.success(__('Reset'));
this.$emit('reset');
this.submitting = false;
},

cancel() {
Expand Down
11 changes: 9 additions & 2 deletions resources/js/components/data-list/Action.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
:title="action.title"
:danger="action.dangerous"
:buttonText="runButtonText"
:submitting="running"
@confirm="confirm"
@cancel="reset"
>
Expand Down Expand Up @@ -71,6 +72,7 @@ export default {
confirming: false,
fieldset: {tabs:[{fields:this.action.fields}]},
values: this.action.values,
running: false,
}
},

Expand Down Expand Up @@ -113,18 +115,23 @@ export default {
},

methods: {
onDone() {
this.running = false;
},

select() {
if (this.action.confirm) {
this.confirming = true;
return;
}

this.$emit('selected', this.action, this.values);
this.running = true;
this.$emit('selected', this.action, this.values, this.onDone);
},

confirm() {
this.$emit('selected', this.action, this.values);
this.running = true;
this.$emit('selected', this.action, this.values, this.onDone);
},

reset() {
Expand Down
17 changes: 10 additions & 7 deletions resources/js/components/data-list/Actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ export default {
},

methods: {

run(action, values) {
run(action, values, done) {
this.$emit('started');

this.errors = {};
Expand All @@ -43,11 +42,15 @@ export default {
values
};

this.$axios.post(this.url, payload, { responseType: 'blob' }).then(response => {
response.headers['content-disposition']
? this.handleFileDownload(response) // Pass blob response for downloads
: this.handleActionSuccess(response); // Otherwise handle as normal, converting from JSON
}).catch(error => this.handleActionError(error.response));
this.$axios
.post(this.url, payload, { responseType: 'blob' })
.then((response) => {
response.headers['content-disposition']
? this.handleFileDownload(response) // Pass blob response for downloads
: this.handleActionSuccess(response); // Otherwise handle as normal, converting from JSON
})
.catch((error) => this.handleActionError(error.response))
.finally(() => done());
},

handleActionSuccess(response) {
Expand Down
35 changes: 23 additions & 12 deletions resources/js/components/modals/ConfirmationModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,25 @@
<header v-if="title" class="text-lg font-semibold px-5 py-3 bg-gray-200 dark:bg-dark-550 rounded-t-lg flex items-center justify-between border-b dark:border-dark-900">
{{ __(title) }}
</header>
<div class="flex-1 px-5 py-6 text-gray dark:text-dark-150">
<slot name="body">
<p v-if="bodyText" v-text="bodyText" />
<slot v-else>
<p>{{ __('Are you sure?') }}</p>

<div class="relative">
<div class="flex-1 px-5 py-6 text-gray dark:text-dark-150" :class="submitting ? ['blur-[2px]', 'opacity-75', 'select-none', 'pointer-events-none'] : []">
<slot name="body">
<p v-if="bodyText" v-text="bodyText"/>
<slot v-else>
<p>{{ __('Are you sure?') }}</p>
</slot>
</slot>
</slot>
</div>
<div v-if="submitting" class="absolute inset-0 flex items-center justify-center">
<loading-graphic text="" />
</div>
</div>
<div class="px-5 py-3 bg-gray-200 dark:bg-dark-550 rounded-b-lg border-t dark:border-dark-900 flex items-center justify-end text-sm">
<button class="btn-flat" @click.prevent="$emit('cancel')" v-text="__(cancelText)" v-if="cancellable" />
<button class="rtl:mr-4 ltr:ml-4" :class="buttonClass" :disabled="disabled" v-text="__(buttonText)" />

<div
class="px-5 py-3 bg-gray-200 dark:bg-dark-550 rounded-b-lg border-t dark:border-dark-900 flex items-center justify-end text-sm">
<button class="btn-flat" @click.prevent="$emit('cancel')" v-text="__(cancelText)" v-if="cancellable" :disabled="submitting"/>
<button class="rtl:mr-4 ltr:ml-4" :class="buttonClass" :disabled="disabled || submitting" v-text="__(buttonText)"/>
</div>
</form>
</modal>
Expand Down Expand Up @@ -48,13 +56,16 @@ export default {
disabled: {
type: Boolean,
default: false,
},
submitting: {
type: Boolean,
default: false,
}
},

data() {
return {
escBinding: null,
enterBinding: null,
}
},

Expand All @@ -69,15 +80,15 @@ export default {
this.$emit('cancel')
},
submit() {
this.$emit('confirm')
this.$emit('confirm');
}
},

created() {
this.escBinding = this.$keys.bind('esc', this.dismiss)
},

beforeDestroy() {
beforeDestroy() {
this.escBinding.destroy()
},
}
Expand Down
4 changes: 3 additions & 1 deletion vite-svg-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ module.exports = function svgLoader (options = {}) {
transformAssetUrls: false
})

return `${code}\nexport default { render: render }`
const template = code instanceof Promise ? await code : code;
morhi marked this conversation as resolved.
Show resolved Hide resolved

return `${template}\nexport default { render: render }`
}
}
}
Expand Down
Loading