Create a custom tinder-like validation view
This example shows you how you can implement a time-saving profile validation view using keyboard keys to trigger approve/reject actions.
In our example, we want to Approve or Reject new customers profiles and more specifically:
  • We want to preview informations from the user's profile
  • We want to approve a customer by pressing the ArrowRight key
  • We want to reject a customer by pressing the ArrowLeft key

How it works

Models definition

Here is the definition of the underlying model for this view
1
module.exports = (sequelize, DataTypes) => {
2
const { Sequelize } = sequelize;
3
const customerValidations = sequelize.define('customerValidations', {
4
firstname: {
5
type: DataTypes.STRING,
6
},
7
lastname: {
8
type: DataTypes.STRING,
9
},
10
email: {
11
type: DataTypes.STRING,
12
},
13
createdAt: {
14
type: DataTypes.DATE,
15
},
16
status: {
17
type: DataTypes.STRING,
18
},
19
avatar: {
20
type: DataTypes.STRING,
21
},
22
}, {
23
tableName: 'customers',
24
underscored: true,
25
schema: process.env.DATABASE_SCHEMA,
26
});
27
28
29
return customerValidations;
30
};
31
Copied!

Smart view definition

Learn more about smart views. This file contains the HTML, JS and CSS needed to build the view.
Template
1
<div class="c-smart-view">
2
<div class="c-smart-view__content">
3
{{#if (eq @recordsCount 0)}}
4
<span class="c-smart-view_icon fa fa-{{@collection.iconOrDefault}} fa-5x"></span>
5
<h1>
6
{{@collection.pluralizedDisplayName}}
7
</h1>
8
<p>
9
There are no items to process.
10
</p>
11
{{/if}}
12
{{#unless (eq @recordsCount 0)}}
13
<div class="wrapper-view" {{did-insert this.setDefaultCurrentRecord}}>
14
<div class="wrapper-list">
15
{{#each @records as |record|}}
16
<div class="list--item align-left {{if (eq @records.firstObject record) 'selected'}}">
17
<div class="list--item__values">
18
<h3><span>name :</span> {{record.forest-firstname}} {{record.forest-lastname}}</h3>
19
<p><span>email :</span> {{record.forest-email}}</p>
20
<p>{{moment-format record.forest-createdAt 'LLL'}}</p>
21
</div>
22
</div>
23
{{/each}}
24
</div>
25
<div class="wrapper-content">
26
<h1>
27
{{@recordsCount}} items to process
28
</h1>
29
<p>
30
Press <i class="fa fa-arrow-right"></i> to approve
31
</p>
32
<p>
33
Press <i class="fa fa-arrow-left"></i> to reject
34
</p>
35
<div class="record-container" >
36
<div class="c-beta-label c-beta-label--top ember-view l-dmb">
37
<div class= "c-beta-label__label">Name</div>
38
<p class="c-row-value align-left">{{@records.firstObject.forest-firstname}} {{@records.firstObject.forest-lastname}}</p>
39
</div>
40
<div class="c-beta-label c-beta-label--top ember-view l-dmb">
41
<div class= "c-beta-label__label">Email</div>
42
<p class="c-row-value align-left">{{@records.firstObject.forest-email}}</p>
43
</div>
44
<div class= "row-value-image">
45
<img src="{{@records.firstObject.forest-avatar}}" width="300" height="400">
46
</div>
47
<div class="c-beta-button c-beta-button--secondary" onclick={{ action 'triggerSmartAction' @collection 'reject' @records.firstObject}}>Reject</div>
48
<div class="c-beta-button c-beta-button--primary" onclick={{ action 'triggerSmartAction' @collection 'approve' @records.firstObject}}>Approve</div>
49
</div>
50
</div>
51
</div>
52
{{/unless}}
53
</div>
54
</div>
Copied!