lbry-desktop/ui/component/syncToggle/view.jsx

60 lines
1.4 KiB
React
Raw Normal View History

2019-10-15 23:23:51 +02:00
// @flow
import * as PAGES from 'constants/pages';
2019-10-15 23:23:51 +02:00
import React from 'react';
import Button from 'component/button';
import { FormField } from 'component/common/form';
import { withRouter } from 'react-router';
2019-10-15 23:23:51 +02:00
type Props = {
setSyncEnabled: boolean => void,
syncEnabled: boolean,
verifiedEmail: ?string,
history: { push: string => void },
location: UrlLocation,
getSyncError: ?string,
disabled: boolean,
2019-10-15 23:23:51 +02:00
};
function SyncToggle(props: Props) {
const {
setSyncEnabled,
syncEnabled,
verifiedEmail,
getSyncError,
history,
location: { pathname },
disabled = false,
} = props;
2019-10-15 23:23:51 +02:00
function handleChange() {
setSyncEnabled(!syncEnabled);
}
if (getSyncError) {
2019-10-16 07:41:49 +02:00
history.push(`/$/${PAGES.AUTH}?redirect=${pathname}&immediate=true`);
return null;
}
2019-10-15 23:23:51 +02:00
return (
<div>
{!verifiedEmail ? (
<div>
<Button requiresAuth button="primary" label={__('Add Email')} />
<p className="help">{__('An email address is required to sync your account.')}</p>
</div>
2019-10-15 23:23:51 +02:00
) : (
<FormField
type="checkbox"
name="sync_toggle"
2019-10-25 17:28:36 +02:00
label={__('Sync your balance and preferences across devices.')}
2019-10-15 23:23:51 +02:00
checked={syncEnabled}
onChange={handleChange}
disabled={disabled}
2019-10-15 23:23:51 +02:00
/>
)}
</div>
);
}
export default withRouter(SyncToggle);