Skip to content

Commit

Permalink
fix: comments
Browse files Browse the repository at this point in the history
  • Loading branch information
borkopetrovicc committed Jul 18, 2023
1 parent 2661185 commit 967073e
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 16 deletions.
1 change: 1 addition & 0 deletions public/locales/en/account.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
"sign_up": "Sign up",
"simultaneous_logins": "The maximum number of active sessions for this account has been reached. Signing in here will sign you out from another session or device.",
"twitter": "Sign in with Twitter",
"unexpected_error": "An unexpected error occurred.",
"view_password": "View password",
"wrong_combination": "Incorrect email/password combination",
"wrong_email": "Please check your email and try again."
Expand Down
1 change: 1 addition & 0 deletions public/locales/es/account.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
"sign_up": "Registrarse",
"simultaneous_logins": "Se ha alcanzado el número máximo de sesiones activas para esta cuenta. Iniciar sesión aquí lo cerrará en otra sesión o dispositivo.",
"twitter": "Inicia sesión con Twitter",
"unexpected_error": "Ocurrió un error inesperado.",
"view_password": "Ver contraseña",
"wrong_combination": "Combinación de correo electrónico/contraseña incorrecta",
"wrong_email": "Por favor, verifica tu correo electrónico e intenta nuevamente."
Expand Down
12 changes: 2 additions & 10 deletions src/components/LoginForm/LoginForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,6 @@ import { addQueryParam } from '#src/utils/location';
import type { FormErrors } from '#types/form';
import type { LoginFormData } from '#types/account';

const LOGIN_FORM_MESSAGES = ['simultaneous_logins'] as const;

export type LoginFormMessage = (typeof LOGIN_FORM_MESSAGES)[number];

const isValidLoginFormMessage = (message: string | undefined): message is LoginFormMessage => LOGIN_FORM_MESSAGES.includes(message as LoginFormMessage);

export const getLoginFormMessage = (message: string | undefined): LoginFormMessage | undefined => (isValidLoginFormMessage(message) ? message : undefined);

type Props = {
onSubmit: React.FormEventHandler<HTMLFormElement>;
onChange: React.ChangeEventHandler<HTMLInputElement | HTMLTextAreaElement>;
Expand All @@ -35,15 +27,15 @@ type Props = {
values: LoginFormData;
submitting: boolean;
siteName?: string;
message?: LoginFormMessage;
message?: string;
};

const LoginForm: React.FC<Props> = ({ onSubmit, onChange, values, errors, submitting, siteName, message }: Props) => {
const [viewPassword, toggleViewPassword] = useToggle();
const { t } = useTranslation('account');
const location = useLocation();

const getTranslatedErrorMessage = (messageId: LoginFormMessage | undefined) => {
const getTranslatedErrorMessage = (messageId: string | undefined) => {
switch (messageId) {
case 'simultaneous_logins':
return t('login.simultaneous_logins');
Expand Down
3 changes: 1 addition & 2 deletions src/containers/AccountModal/AccountModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import WaitingForPayment from '#components/WaitingForPayment/WaitingForPayment';
import UpdatePaymentMethod from '#src/containers/UpdatePaymentMethod/UpdatePaymentMethod';
import useEventCallback from '#src/hooks/useEventCallback';
import UpgradeSubscription from '#components/UpgradeSubscription/UpgradeSubscription';
import { getLoginFormMessage } from '#components/LoginForm/LoginForm';

const PUBLIC_VIEWS = ['login', 'create-account', 'forgot-password', 'reset-password', 'send-confirmation', 'edit-password', 'simultaneous-logins'];

Expand Down Expand Up @@ -76,7 +75,7 @@ const AccountModal = () => {

switch (view) {
case 'login':
return <Login message={getLoginFormMessage(message)} />;
return <Login message={message} />;
case 'create-account':
return <Registration />;
case 'personal-details':
Expand Down
4 changes: 2 additions & 2 deletions src/containers/AccountModal/forms/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import { useLocation, useNavigate } from 'react-router';

import { useConfigStore } from '#src/stores/ConfigStore';
import useForm, { UseFormOnSubmitHandler } from '#src/hooks/useForm';
import LoginForm, { LoginFormMessage } from '#components/LoginForm/LoginForm';
import LoginForm from '#components/LoginForm/LoginForm';
import { removeQueryParam } from '#src/utils/location';
import type { LoginFormData } from '#types/account';
import { login } from '#src/stores/AccountController';

type Props = {
message?: LoginFormMessage;
message?: string;
};

const Login: React.FC<Props> = ({ message }: Props) => {
Expand Down
3 changes: 1 addition & 2 deletions src/stores/NotificationsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { logout, reloadActiveSubscription } from './AccountController';

import useService from '#src/hooks/useService';
import { addQueryParams } from '#src/utils/formatting';
import type { LoginFormMessage } from '#components/LoginForm/LoginForm';

export enum NotificationsTypes {
ACCESS_GRANTED = 'access.granted',
Expand All @@ -27,7 +26,7 @@ export const subscribeToNotifications = async (uuid: string = '') => {
case NotificationsTypes.ACCOUNT_LOGOUT:
await logout();
if (notification.resource?.reason === 'sessions_limit') {
const message: LoginFormMessage = 'simultaneous_logins';
const message: string = 'simultaneous_logins';
window.location.href = addQueryParams(window.location.href, { u: 'login', message });
}
break;
Expand Down

0 comments on commit 967073e

Please sign in to comment.