-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate.js
More file actions
30 lines (21 loc) · 681 Bytes
/
Copy pathcreate.js
File metadata and controls
30 lines (21 loc) · 681 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import Component from '@glimmer/component';
import { service } from '@ember/service';
export default class PagesUsersCreate extends Component {
@service router;
handleSubmit = async (e) => {
e.preventDefault();
const fd = new FormData(e.target);
const payload = {
name: fd.get('name'),
favoriteColor: fd.get('favoriteColor'),
}
const res = await fetch('/users', {
method: 'POST',
body: JSON.stringify({ user: payload }),
});
if (!res.ok) throw new Error('unable to create user!');
const { user } = await res.json();
alert('created user with id', user.id);
this.router.transitionTo('users.list');
}
}