Unverified Commit bb189ca8 authored by Renato Becker's avatar Renato Becker Committed by GitHub

Sort departments on Forms (#205)

* Add department field on Offline Message Form.

* Removed `id` from form components.

* Sort departments by name.
parent 698b3565
......@@ -116,6 +116,13 @@ export const getAttachmentsUrl = (attachments) => attachments && attachments.map
return { ...attachment, attachment_url: `${ Livechat.client.host }${ assetUrl }` };
});
export const sortArrayByColumn = (array, column, inverted) => array.sort((a, b) => {
if (a[column] < b[column] && !inverted) {
return -1;
}
return 1;
});
export const normalizeDOMRect = (({ left, top, right, bottom }) => ({ left, top, right, bottom }));
......
......@@ -2,7 +2,7 @@ import { Component } from 'preact';
import Button from '../../components/Button';
import Form, { Validations } from '../../components/Form';
import Screen from '../../components/Screen';
import { createClassName } from '../../components/helpers';
import { createClassName, sortArrayByColumn } from '../../components/helpers';
import styles from './styles';
......@@ -124,7 +124,7 @@ export default class LeaveMessage extends Component {
<Form.SelectInput
name="department"
placeholder={I18n.t('Choose an option...')}
options={departments.map(({ _id, name }) => ({ value: _id, label: name }))}
options={sortArrayByColumn(departments, 'name').map(({ _id, name }) => ({ value: _id, label: name }))}
disabled={loading}
value={department.value}
error={department.showError}
......
......@@ -2,7 +2,7 @@ import { Component } from 'preact';
import Button from '../../components/Button';
import Form, { Validations } from '../../components/Form';
import Screen from '../../components/Screen';
import { createClassName } from '../../components/helpers';
import { createClassName, sortArrayByColumn } from '../../components/helpers';
import styles from './styles';
......@@ -168,7 +168,7 @@ export default class Register extends Component {
id="department"
name="department"
placeholder={I18n.t('Choose an option...')}
options={departments.map(({ _id, name }) => ({ value: _id, label: name }))}
options={sortArrayByColumn(departments, 'name').map(({ _id, name }) => ({ value: _id, label: name }))}
disabled={loading}
value={department.value}
error={department.showError}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment