Skip to content
This repository was archived by the owner on Oct 11, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ describe('private community invite link settings', () => {
// grab the input again and compare its previous value
// to the current value
cy.get('[data-cy="join-link-input"]')
.scrollIntoView()
.invoke('val')
.should(val2 => {
expect(val1).not.to.eq(val2);
Expand All @@ -51,6 +52,7 @@ describe('private community invite link settings', () => {

// disable
cy.get('[data-cy="toggle-token-link-invites-checked"]')
.scrollIntoView()
.should('be.visible')
.click();

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"cors": "^2.8.3",
"cryptr": "^3.0.0",
"css.escape": "^1.5.1",
"cypress": "^3.1.3",
"cypress": "3.1.5",
"datadog-metrics": "^0.8.1",
"dataloader": "^1.4.0",
"debounce": "^1.2.0",
Expand Down
133 changes: 120 additions & 13 deletions src/components/emailInvitationForm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@ import { Button } from '../buttons';
import { Error } from '../formElements';
import { SectionCardFooter } from 'src/components/settingsViews/style';
import { withCurrentUser } from 'src/components/withCurrentUser';
import MediaInput from 'src/components/mediaInput';
import {
EmailInviteForm,
EmailInviteInput,
AddRow,
Action,
ActionAsLabel,
ActionHelpText,
RemoveRow,
CustomMessageToggle,
CustomMessageTextAreaStyles,
HiddenInput,
} from './style';

type Props = {
Expand All @@ -37,16 +41,20 @@ type ContactProps = {
type State = {
isLoading: boolean,
contacts: Array<ContactProps>,
importError: string,
hasCustomMessage: boolean,
customMessageString: string,
customMessageError: boolean,
inputValue: ?string,
};

class EmailInvitationForm extends React.Component<Props, State> {
constructor() {
super();
constructor(props) {
super(props);

this.state = {
isLoading: false,
importError: '',
contacts: [
{
email: '',
Expand All @@ -70,6 +78,7 @@ class EmailInvitationForm extends React.Component<Props, State> {
hasCustomMessage: false,
customMessageString: '',
customMessageError: false,
inputValue: '',
};
}

Expand All @@ -87,7 +96,7 @@ class EmailInvitationForm extends React.Component<Props, State> {
this.setState({ isLoading: true });

let validContacts = contacts
.filter(contact => contact.error === false)
.filter(contact => !contact.error)
.filter(contact => contact.email !== currentUser.email)
.filter(contact => contact.email.length > 0)
.filter(contact => isEmail(contact.email))
Expand Down Expand Up @@ -234,17 +243,102 @@ class EmailInvitationForm extends React.Component<Props, State> {
});
};

handleFile = evt => {
this.setState({
importError: '',
});

// Only show loading indicator for large files
// where it takes > 200ms to load
const timeout = setTimeout(() => {
this.setState({
isLoading: true,
});
}, 200);

const reader = new FileReader();
reader.onload = file => {
clearTimeout(timeout);
this.setState({
isLoading: false,
});

let parsed;
try {
if (typeof reader.result !== 'string') return;
parsed = JSON.parse(reader.result);
} catch (err) {
this.setState({
importError: 'Only .json files are supported for import.',
});
return;
}

if (!Array.isArray(parsed)) {
this.setState({
importError:
'Your JSON data is in the wrong format. Please provide either an array of emails ["hi@me.com"] or an array of objects with an "email" property and (optionally) a "name" property [{ "email": "hi@me.com", "name": "Me" }].',
});
return;
}

const formatted = parsed.map(value => {
if (typeof value === 'string')
return {
email: value,
};

return {
email: value.email,
firstName: value.firstName || value.name,
lastName: value.lastName,
};
});

const validated = formatted
.map(value => {
if (!isEmail(value.email)) return { ...value, error: true };
return value;
})
.filter(Boolean);

const consolidated = [
...this.state.contacts.filter(
contact =>
contact.email.length > 0 ||
contact.firstName.length > 0 ||
contact.lastName.length > 0
),
...validated,
];

const unique = consolidated.filter(
(obj, i) =>
consolidated.findIndex(a => a['email'] === obj['email']) === i
);

this.setState({
contacts: unique,
inputValue: '',
});
};

reader.readAsText(evt.target.files[0]);
};

render() {
const {
contacts,
isLoading,
hasCustomMessage,
customMessageString,
customMessageError,
importError,
} = this.state;

return (
<div>
{importError && <Error>{importError}</Error>}
{contacts.map((contact, i) => {
return (
<EmailInviteForm key={i}>
Expand All @@ -270,14 +364,28 @@ class EmailInvitationForm extends React.Component<Props, State> {
);
})}

<AddRow onClick={this.addRow}>+ Add another</AddRow>
<Action onClick={this.addRow}>
<Icon glyph="plus" size={20} /> Add row
</Action>
<ActionAsLabel mb="8px">
<HiddenInput
value={this.state.inputValue}
type="file"
accept=".json"
onChange={this.handleFile}
/>
<Icon size={20} glyph="upload" /> Import emails
</ActionAsLabel>
<ActionHelpText>
Upload a .json file with an array of email addresses.
</ActionHelpText>

<CustomMessageToggle onClick={this.toggleCustomMessage}>
<Action onClick={this.toggleCustomMessage}>
<Icon glyph={hasCustomMessage ? 'view-close' : 'post'} size={20} />
{hasCustomMessage
? 'Remove custom message'
: 'Optional: Add a custom message to your invitation'}
</CustomMessageToggle>
</Action>

{hasCustomMessage && (
<Textarea
Expand All @@ -294,12 +402,11 @@ class EmailInvitationForm extends React.Component<Props, State> {
/>
)}

{hasCustomMessage &&
customMessageError && (
<Error>
Your custom invitation message can be up to 500 characters.
</Error>
)}
{hasCustomMessage && customMessageError && (
<Error>
Your custom invitation message can be up to 500 characters.
</Error>
)}

<SectionCardFooter>
<Button
Expand Down
28 changes: 25 additions & 3 deletions src/components/emailInvitationForm/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,43 @@ export const EmailInviteInput = styled.input`
}
`;

export const AddRow = styled.div`
export const HiddenInput = styled.input`
display: none;
`;

export const Action = styled.button`
display: flex;
width: 100%;
justify-content: center;
padding: 8px;
background: ${theme.bg.wash};
margin-top: 8px;
margin-bottom: 16px;
margin-bottom: ${props => props.mb || '16px'};
font-size: 14px;
color: ${theme.text.alt};
font-weight: 500;
border-radius: 4px;

.icon {
margin-right: 4px;
}

&:hover {
color: ${theme.text.default};
color: ${theme.text.secondary};
cursor: pointer;
}
`;

export const ActionAsLabel = Action.withComponent('label');

export const ActionHelpText = styled.div`
color: ${theme.text.alt};
font-size: 14px;
text-align: center;
margin-top: 8px;
margin-bottom: 24px;
`;

export const RemoveRow = styled.div`
margin-left: 4px;
color: ${theme.text.alt};
Expand Down Expand Up @@ -86,6 +104,10 @@ export const CustomMessageToggle = styled.h4`
}
`;

export const FileUploadWrapper = styled.div`
margin-right: 16px;
`;

export const CustomMessageTextAreaStyles = {
width: '100%',
borderRadius: '8px',
Expand Down
8 changes: 8 additions & 0 deletions src/components/icons/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 4 additions & 6 deletions src/components/mediaInput/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ export default ({
onChange,
accept = '.png, .jpg, .jpeg, .gif, .mp4',
multiple = false,
tipLocation,
tipLocation = 'top-right',
tipText = 'Upload photo',
glyph = 'photo',
}) => (
<MediaLabel>
<MediaInput
Expand All @@ -15,10 +17,6 @@ export default ({
multiple={multiple}
onChange={onChange}
/>
<Icon
glyph="photo"
tipLocation={tipLocation ? tipLocation : 'top-right'}
tipText="Upload photo"
/>
<Icon glyph={glyph} tipLocation={tipLocation} tipText={tipText} />
</MediaLabel>
);
5 changes: 5 additions & 0 deletions upload.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading