Mailspring/app/internal_packages/onboarding/lib/page-account-settings.tsx
Ben Gotow 149b389508
Replace Babel with TypeScript compiler, switch entire app to TypeScript 🎉 (#1404)
* Switch to using Typescript instead of Babel

* Switch all es6 / jsx file extensions to ts / tsx

* Convert Utils to a TS module from module.exports style module

* Move everything from module.exports to typescript exports

* Define .d.ts files for mailspring-exports and component kit… Yes it seems this is the best option :(

* Load up on those @types

* Synthesize TS types from PropTypes for standard components

* Add types to Model classes and move constructor constants to instance vars

* 9800 => 7700 TS errors

* 7700 => 5600 TS errors

* 5600 => 5330 TS errors

* 5330 => 4866 TS errors

* 4866 => 4426 TS errors

* 4426 => 2411 TS errors

* 2411 > 1598 TS errors

* 1598 > 769 TS errors

* 769 > 129 TS errors

* 129 > 22 TS errors

* Fix runtime errors

* More runtime error fixes

* Remove support for custom .es6 file extension

* Remove a few odd remaining references to Nylas

* Don’t ship Typescript support in the compiled app for now

* Fix issues in compiled app - module resolution in TS is case sensitive?

* README updates

* Fix a few more TS errors

* Make “No Signature” option clickable + selectable

* Remove flicker when saving file and reloading keymaps

* Fix mail rule item height in preferences

* Fix missing spacing in thread sharing popover

* Fix scrollbar ticks being nested incorrectly

* Add Japanese as a manually reviewed language

* Prevent the thread list from “sticking”

* Re-use Sheet when switching root tabs, prevent sidebar from resetting

* Ensure specs run

* Update package configuration to avoid shpping types

* Turn eslint back on - we will opt-in to the TS rules one by one
2019-03-04 11:03:12 -08:00

100 lines
3.2 KiB
TypeScript

import React from 'react';
import { localized, Account, PropTypes, RegExpUtils } from 'mailspring-exports';
import * as OnboardingActions from './onboarding-actions';
import CreatePageForForm from './decorators/create-page-for-form';
import { expandAccountWithCommonSettings } from './onboarding-helpers';
import FormField from './form-field';
interface AccountBasicSettingsFormProps {
account: Account;
errorFieldNames: string[];
submitting: boolean;
onConnect: (account: Account) => void;
onFieldChange: () => void;
onFieldKeyPress: () => void;
}
class AccountBasicSettingsForm extends React.Component<AccountBasicSettingsFormProps> {
static displayName = 'AccountBasicSettingsForm';
static submitLabel = account => {
return account.provider === 'imap' ? localized('Continue') : localized('Connect Account');
};
static titleLabel = providerConfig => {
return (
providerConfig.title ||
localized(
`Add your %@ account`,
providerConfig.displayNameShort || providerConfig.displayName
)
);
};
static subtitleLabel = providerConfig => {
return (
providerConfig.note ||
localized(
`Enter your email account credentials to get started. Mailspring\nstores your email password securely and it is never sent to our servers.`
)
);
};
static validateAccount = account => {
const errorFieldNames = [];
let errorMessage = null;
if (!account.emailAddress || !account.settings.imap_password || !account.name) {
return { errorMessage, errorFieldNames, populated: false };
}
if (!RegExpUtils.emailRegex().test(account.emailAddress)) {
errorFieldNames.push('email');
errorMessage = localized('Please provide a valid email address.');
}
if (!account.name) {
errorFieldNames.push('name');
errorMessage = localized('Please provide your name.');
}
if (!account.settings.imap_password) {
errorFieldNames.push('password');
errorMessage = localized('Please provide a password for your account.');
}
return { errorMessage, errorFieldNames, populated: true };
};
async submit() {
// create a new account with expanded settings and just the three fields
const { name, emailAddress, provider, settings: { imap_password } } = this.props.account;
let account = new Account({ name, emailAddress, provider, settings: { imap_password } });
account = await expandAccountWithCommonSettings(account);
OnboardingActions.setAccount(account);
if (account.settings.imap_host && account.settings.smtp_host) {
// expanding the account settings succeeded - try to authenticate
this.props.onConnect(account);
} else {
// we need the user to provide IMAP/SMTP credentials manually
OnboardingActions.moveToPage('account-settings-imap');
}
}
render() {
return (
<form className="settings">
<FormField field="name" title={localized('Name')} {...this.props} />
<FormField field="emailAddress" title={localized('Email')} {...this.props} />
<FormField
field="settings.imap_password"
title="Password"
type="password"
{...this.props}
/>
</form>
);
}
}
export default CreatePageForForm(AccountBasicSettingsForm);