Commit d7fa44a7 authored by Rejo Zenger's avatar Rejo Zenger

Merge branch 'revert-a199f8dd' into 'master'

Revert "Merge branch 'feature/duplicate-identifiers' into 'master'"

See merge request !106
parents a199f8dd 4d8f43c2
import * as React from 'react';
import { v4 as uuid } from 'uuid';
import { Checkbox, Group, Input } from 'components/Form';
import withRequest, { IWithRequestProps } from 'components/Request/withRequest';
......@@ -6,7 +7,6 @@ import { Request } from 'lib/constants';
import { patchIdx } from 'lib/utils';
interface IIdentityProps extends IWithRequestProps {
id: string;
title: string;
placeholder: string;
defaultValue?: string;
......@@ -15,7 +15,7 @@ interface IIdentityProps extends IWithRequestProps {
class Identity extends React.PureComponent<IIdentityProps, never> {
onToggle = (checked: boolean) => {
const { id, request, title, defaultValue } = this.props;
const { request, title, defaultValue } = this.props;
request.set(prevRequest => {
const identifiers: Request.IIdentifier[] =
(prevRequest as Request.IAttributes).identifiers || [];
......@@ -25,7 +25,7 @@ class Identity extends React.PureComponent<IIdentityProps, never> {
identifiers: [
...identifiers,
{
id: id,
id: uuid(),
name: title,
value: defaultValue || ''
}
......@@ -57,17 +57,17 @@ class Identity extends React.PureComponent<IIdentityProps, never> {
};
render() {
const { id, title, placeholder, defaultValue, type, request } = this.props;
const { title, placeholder, defaultValue, type, request } = this.props;
const identifiers: Request.IIdentifier[] =
(request as Request.IAttributes).identifiers || [];
const identity = identifiers.find(identifier => identifier.id === id);
const identity = identifiers.find(identifier => identifier.name === title);
return (
<Group>
<Checkbox
checked={!!identity}
onToggle={this.onToggle}
label={identity ? identity.name : title}
label={title}
packed
/>
......
......@@ -112,7 +112,6 @@ class Identify extends React.PureComponent<IIdentifyProps, never> {
: ['email', 'customer_number'];
const presetIdentifiers = selectedIdentifiers
.map(key => ({
id: `preset.${key}`,
title: t(`request.attributes.${key}.title`, { defaultValue: key }),
value: contactDetails[key] || '',
placeholder: t(`request.attributes.${key}.placeholder`, {
......@@ -123,7 +122,7 @@ class Identify extends React.PureComponent<IIdentifyProps, never> {
const customIdentifiers = identifiers.filter(
identifier =>
presetIdentifiers.map(id => id.id).indexOf(identifier.id) === -1
presetIdentifiers.map(id => id.title).indexOf(identifier.name) === -1
);
return (
......@@ -145,11 +144,10 @@ class Identify extends React.PureComponent<IIdentifyProps, never> {
onChange={this.onChangeName}
/>
{presetIdentifiers.map(({ id, title, placeholder, value }) => (
{presetIdentifiers.map(({ title, placeholder, value }) => (
<Identity
key={title}
type="text"
id={id}
title={title}
defaultValue={value}
placeholder={placeholder}
......
......@@ -27,7 +27,7 @@ class Response extends React.PureComponent<IResponseProps, never> {
}
onSelect = (type: Request.CommunicationMethod) => () => {
const { request } = this.props;
const { t, request } = this.props;
request.set(prevRequest => {
const {
......@@ -39,7 +39,9 @@ class Response extends React.PureComponent<IResponseProps, never> {
// Check if we already have a type from the previous identify screen and pre-populate the email method
if (!knownEmail) {
const identity = identifiers.find(ident => ident.id === 'preset.email');
const identity = identifiers.find(
ident => ident.name === t('request.attributes.email.title')
);
if (identity && identity.value) {
knownEmail = identity.value;
......
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