Skip to content

Commit b66a163

Browse files
committed
crate/delete: Add required reason input field
1 parent 2807030 commit b66a163

File tree

6 files changed

+34
-3
lines changed

6 files changed

+34
-3
lines changed

app/controllers/crate/delete.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,18 @@ export default class CrateSettingsController extends Controller {
99
@service notifications;
1010
@service router;
1111

12+
@tracked reason = '';
1213
@tracked isConfirmed;
1314

1415
@action toggleConfirmation() {
1516
this.isConfirmed = !this.isConfirmed;
1617
}
1718

1819
deleteTask = task(async () => {
20+
let { reason } = this;
21+
1922
try {
20-
await this.model.destroyRecord();
23+
await this.model.destroyRecord({ adapterOptions: { reason } });
2124
this.notifications.success(`Crate ${this.model.name} has been successfully deleted.`);
2225
this.router.transitionTo('index');
2326
} catch (error) {

app/routes/crate/delete.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export default class SettingsRoute extends AuthenticatedRoute {
2020

2121
setupController(controller) {
2222
super.setupController(...arguments);
23+
controller.set('reason', '');
2324
controller.set('isConfirmed', false);
2425
}
2526
}

app/styles/crate/delete.module.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,15 @@
7575
}
7676
}
7777

78+
.reason {
79+
margin-bottom: var(--space-m);
80+
}
81+
82+
.reason-input {
83+
composes: base-input from '../../styles/settings/tokens/new.module.css';
84+
width: 100%;
85+
}
86+
7887
.confirmation {
7988
composes: warning-block;
8089
display: block;

app/templates/crate/delete.hbs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,20 @@
3636
</ol>
3737
</div>
3838

39+
<div local-class="reason">
40+
<h3>Reason:</h3>
41+
<label>
42+
<p>Please tell us why you are deleting this crate:</p>
43+
<Input
44+
@type="text"
45+
@value={{this.reason}}
46+
required={{true}}
47+
local-class="reason-input"
48+
data-test-reason
49+
/>
50+
</label>
51+
</div>
52+
3953
<label local-class="confirmation">
4054
<Input
4155
@type="checkbox"

tests/acceptance/crate-deletion-test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { click, currentURL } from '@ember/test-helpers';
1+
import { click, currentURL, fillIn } from '@ember/test-helpers';
22
import { module, test } from 'qunit';
33

44
import { setupApplicationTest } from 'crates-io/tests/helpers';
@@ -29,6 +29,7 @@ module('Acceptance | crate deletion', function (hooks) {
2929
assert.dom('[data-test-title]').hasText('Delete the foo crate?');
3030
assert.dom('[data-test-delete-button]').isDisabled();
3131

32+
await fillIn('[data-test-reason]', "I don't need this crate anymore");
3233
await click('[data-test-confirmation-checkbox]');
3334
assert.dom('[data-test-delete-button]').isEnabled();
3435

tests/routes/crate/delete-test.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { click, currentURL, waitFor } from '@ember/test-helpers';
1+
import { click, currentURL, fillIn, waitFor } from '@ember/test-helpers';
22
import { module, test } from 'qunit';
33

44
import { defer } from 'rsvp';
@@ -58,6 +58,7 @@ module('Route: crate.delete', function (hooks) {
5858
assert.dom('[data-test-title]').hasText('Delete the foo crate?');
5959
await percySnapshot(assert);
6060

61+
await fillIn('[data-test-reason]', "I don't need this crate anymore");
6162
assert.dom('[data-test-delete-button]').isDisabled();
6263
await click('[data-test-confirmation-checkbox]');
6364
assert.dom('[data-test-delete-button]').isEnabled();
@@ -79,6 +80,7 @@ module('Route: crate.delete', function (hooks) {
7980
this.server.delete('/api/v1/crates/foo', deferred.promise);
8081

8182
await visit('/crates/foo/delete');
83+
await fillIn('[data-test-reason]', "I don't need this crate anymore");
8284
await click('[data-test-confirmation-checkbox]');
8385
let clickPromise = click('[data-test-delete-button]');
8486
await waitFor('[data-test-spinner]');
@@ -98,6 +100,7 @@ module('Route: crate.delete', function (hooks) {
98100
this.server.delete('/api/v1/crates/foo', payload, 422);
99101

100102
await visit('/crates/foo/delete');
103+
await fillIn('[data-test-reason]', "I don't need this crate anymore");
101104
await click('[data-test-confirmation-checkbox]');
102105
await click('[data-test-delete-button]');
103106
assert.strictEqual(currentURL(), '/crates/foo/delete');

0 commit comments

Comments
 (0)