Skip to content

Commit

Permalink
feat(preferences): not logged in segment (#649)
Browse files Browse the repository at this point in the history
* feat(preferences): not logged in segment

* Update app/assets/javascripts/preferences/panes/account/Authentication.tsx

Co-authored-by: Mo Bitar <[email protected]>

* Update app/assets/javascripts/preferences/panes/account/Authentication.tsx

Co-authored-by: Mo Bitar <[email protected]>

Co-authored-by: Mo Bitar <[email protected]>
  • Loading branch information
gorjan5sk and Mo Bitar authored Sep 27, 2021
1 parent 150f7a7 commit b312df4
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 12 deletions.
4 changes: 2 additions & 2 deletions app/assets/javascripts/preferences/components/Content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ export const Title: FunctionComponent = ({ children }) => (
<h2 className="text-base m-0 mb-1">{children}</h2>
);

export const Subtitle: FunctionComponent = ({ children }) => (
<h4 className="font-medium text-sm m-0 mb-1">{children}</h4>
export const Subtitle: FunctionComponent<{ className?: string }> = ({ children, className = "" }) => (
<h4 className={`font-medium text-sm m-0 mb-1 ${className}`}>{children}</h4>
);

export const Text: FunctionComponent<{ className?: string }> = ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ export const PreferencesPane: FunctionComponent = ({ children }) => (
<div className="w-125 max-w-125 flex flex-col">
{children != undefined && Array.isArray(children)
? children
.filter((child) => child != undefined)
.map((child) => (
<>
{child}
<div className="min-h-3" />
</>
))
.filter((child) => child != undefined)
.map((child) => (
<>
{child}
<div className="min-h-3" />
</>
))
: children}
</div>
</div>
Expand Down
12 changes: 12 additions & 0 deletions app/assets/javascripts/preferences/panes/AccountPreferences.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
SubscriptionWrapper,
Credentials,
LogOutWrapper,
Authentication,
} from '@/preferences/panes/account';
import { PreferencesPane } from '@/preferences/components';
import { observer } from 'mobx-react-lite';
Expand All @@ -16,6 +17,17 @@ type Props = {

export const AccountPreferences = observer(
({ application, appState }: Props) => {
const isLoggedIn = application.getUser();

if (!isLoggedIn) {
return (
<PreferencesPane>
<Authentication application={application} appState={appState} />
<LogOutWrapper application={application} appState={appState} />
</PreferencesPane>
);
}

return (
<PreferencesPane>
<Credentials application={application} />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Button } from "@/components/Button";
import { PreferencesGroup, PreferencesSegment, Subtitle, Text, Title } from "@/preferences/components";
import { WebApplication } from "@/ui_models/application";
import { AppState } from "@/ui_models/app_state";
import { observer } from "mobx-react-lite";
import { FunctionComponent } from "preact";

export const Authentication: FunctionComponent<{ application: WebApplication, appState: AppState }> =
observer(({ appState }) => {

const clickSignIn = () => {
appState.preferences.closePreferences();
appState.accountMenu.setShowLogin(true);
appState.accountMenu.setShow(true);
};

const clickRegister = () => {
appState.preferences.closePreferences();
appState.accountMenu.setShowRegister(true);
appState.accountMenu.setShow(true);
};

return (
<PreferencesGroup>
<PreferencesSegment>
<div className="flex flex-col items-center px-12">
<Title>You're not signed in</Title>
<Subtitle className="text-center">Sign in to sync your notes and preferences across all your devices and enable end-to-end encryption.</Subtitle>
<div className="min-h-3" />
<div className="flex flex-row w-full">
<Button type="primary" onClick={clickSignIn} label="Sign in" className="flex-grow" />
<div className="min-w-3" />
<Button type="primary" onClick={clickRegister} label="Register" className="flex-grow" />
</div>
<div className="min-h-3" />
<Text className="text-center">Standard Notes is free on every platform, and comes standard with sync and encryption.</Text>
</div>
</PreferencesSegment>
</PreferencesGroup>
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import { dateToLocalizedString } from '@/utils';
import { useState } from 'preact/hooks';
import { ChangeEmail } from '@/preferences/panes/account/changeEmail';
import { PasswordWizardType } from '@/types';
import { FunctionComponent } from 'preact';

type Props = {
application: WebApplication;
};

export const Credentials = observer(({ application }: Props) => {
export const Credentials: FunctionComponent<Props> = observer(({ application }: Props) => {
const [isChangeEmailDialogOpen, setIsChangeEmailDialogOpen] = useState(false);

const user = application.getUser();
Expand Down
3 changes: 2 additions & 1 deletion app/assets/javascripts/preferences/panes/account/Sync.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import { useState } from '@node_modules/preact/hooks';
import { dateToLocalizedString } from '@/utils';
import { observer } from '@node_modules/mobx-react-lite';
import { WebApplication } from '@/ui_models/application';
import { FunctionComponent } from 'preact';

type Props = {
application: WebApplication;
};

export const Sync = observer(({ application }: Props) => {
export const Sync: FunctionComponent<Props> = observer(({ application }: Props) => {
const formatLastSyncDate = (lastUpdatedDate: Date) => {
return dateToLocalizedString(lastUpdatedDate);
};
Expand Down
1 change: 1 addition & 0 deletions app/assets/javascripts/preferences/panes/account/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export { SubscriptionWrapper } from './subscription/SubscriptionWrapper';
export { Sync } from './Sync';
export { Credentials } from './Credentials';
export { LogOutWrapper } from './LogOutView';
export { Authentication } from './Authentication';
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ import { SubscriptionInformation } from './SubscriptionInformation';
import { NoSubscription } from './NoSubscription';
import { Text } from '@/preferences/components';
import { observer } from 'mobx-react-lite';
import { FunctionComponent } from 'preact';

type Props = {
application: WebApplication;
subscriptionState: SubscriptionState;
};

export const Subscription = observer(({
export const Subscription: FunctionComponent<Props> = observer(({
application,
subscriptionState,
}: Props) => {
Expand Down
5 changes: 5 additions & 0 deletions app/assets/stylesheets/_sn.scss
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,11 @@
padding-right: 2.25rem;
}

.px-12 {
padding-left: 3rem;
padding-right: 3rem;
}

.py-9 {
padding-top: 2.25rem;
padding-bottom: 2.25rem;
Expand Down

0 comments on commit b312df4

Please sign in to comment.