Skip to content

Commit

Permalink
task(core): apply scss modules: admin & login [#94]
Browse files Browse the repository at this point in the history
  • Loading branch information
Drapegnik committed Mar 12, 2020
1 parent ab3f571 commit e86d149
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 35 deletions.
2 changes: 1 addition & 1 deletion components/admin/AdminSidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const IGNORE_ROUTES = ['login', 'preview'].map(page => ROUTES_NAMES.admin[page])
const AdminSidebar = () => {
const router = useRouter();
return (
<div className={b()}>
<div>
<ul className={b('nav-list')}>
{ADMIN_ROUTES.filter(({ name }) => !IGNORE_ROUTES.includes(name)).map(({ name, page }) => (
<li key={name}>
Expand Down
10 changes: 7 additions & 3 deletions components/auth/FormField.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
import React from 'react';
import PropTypes from 'prop-types';
import { ErrorMessage } from 'formik';
import block from 'bem-css-modules';

import Icon from 'components/common/ui/Icon';
import Text from 'components/common/Text';
import styles from './login-form.module.scss';

const b = block(styles);

const FormField = ({ id, label, icon, children, pending, touched, error }) => {
const hasError = !pending && touched && error;
return (
<div className="login-form__input-wrap">
<label className="login-form__input-label" htmlFor={id}>
<div className={b('input-wrap')}>
<label className={b('input-label')} htmlFor={id}>
<Icon name={icon} /> {label || <Text id={`auth.${id}`} />}
</label>
{children(hasError)}
<ErrorMessage name={id}>
{message => (
<p className="login-form__input-error-message">
<p className={b('input-error-message')}>
<Text id={message} />
</p>
)}
Expand Down
19 changes: 10 additions & 9 deletions components/auth/LoginForm.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import './login-form.scss';

import React from 'react';
import cn from 'classnames';
import { Form, Field } from 'formik';
import block from 'bem-css-modules';

import { validEmail, required, checkLength, hasErrors } from 'utils/validators';
import FormWrapper from 'components/common/form/FormWrapper';
import Button from 'components/common/Button';
import Text from 'components/common/Text';

import { authActions } from 'redux/ducks/auth';
import styles from './login-form.module.scss';

import FormField from './FormField';

const b = block(styles);

const LOGIN_INITIAL_FORM = {
isSignUp: false,
firstName: '',
Expand Down Expand Up @@ -77,8 +78,8 @@ const loginValidator = values =>
}, {});

const LoginForm = () => (
<div className="login-form">
<div className="login-form__title">
<div className={b()}>
<div className={b('title')}>
<Text id="auth.signIn" />
</div>
<FormWrapper
Expand Down Expand Up @@ -112,17 +113,17 @@ const LoginForm = () => (
{hasError => (
<Field
id={id}
className={cn('login-form__input', { 'login-form__input-error': hasError })}
className={b('input', { error: !!hasError })}
name={id}
type={type}
/>
)}
</FormField>
))}
<div className="login-form__btn-container">
<div className="login-form__btn-wrap">
<div className={b('btn-container')}>
<div className={b('btn-wrap')}>
<Button
className="login-form__btn"
className={b('btn')}
type="submit"
disabled={hasErrors(errors, touched)}
pending={isSubmitting}
Expand Down
2 changes: 1 addition & 1 deletion components/auth/login-form.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
color: $primary;
}

&-error {
&--error {
border-color: $error;
}

Expand Down
8 changes: 4 additions & 4 deletions components/common/Table.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import './ui/table.scss';

import React from 'react';
import PropTypes from 'prop-types';
import identity from 'lodash/identity';
import get from 'lodash/get';
import cn from 'classnames';

import { toTitleCase } from 'utils/formatters';
import styles from './ui/table.module.scss';

const renderValue = ({ value }) => value;

Expand Down Expand Up @@ -44,7 +43,7 @@ const Table = ({ className, cols, rows, getRowClass }) => (
);

Table.propTypes = {
className: PropTypes.string,
className: PropTypes.string.isRequired,
rows: PropTypes.arrayOf(
PropTypes.shape({
id: PropTypes.string.isRequired,
Expand All @@ -63,8 +62,9 @@ Table.propTypes = {
};

Table.defaultProps = {
className: 'wir-table',
getRowClass: () => '',
};

export { styles };

export default Table;
2 changes: 1 addition & 1 deletion components/common/Text.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const extract = key => {
};

export const localize = (id, lang) =>
extract(`${id}.${lang}`) || extract(`${id}.${DEFAULT_LOCALE}`);
extract(`${id}.${lang}`) || extract(`${id}.${DEFAULT_LOCALE}`) || id;

export const useLocaleContext = () => useContext(LocaleContext);

Expand Down
4 changes: 4 additions & 0 deletions components/common/layout/layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,7 @@ footer {
padding-right: calc((100% - #{map-get($page-content, mobile)}) * 2 / 3);
}
}

.nowrap {
white-space: nowrap;
}
8 changes: 2 additions & 6 deletions components/common/ui/table.module.scss
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
// FIXME
/* stylelint-disable selector-max-compound-selectors, no-descending-specificity */

.nowrap {
white-space: nowrap;
}

.wir-table {
border-spacing: 0;

Expand Down Expand Up @@ -79,11 +75,11 @@
}
}

&--font-large {
&__font--size--large {
font-size: 1.2rem;
}

&--font-small {
&__font--size--small {
font-size: 0.7rem;
}
}
16 changes: 9 additions & 7 deletions pages/admin/articles.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React, { useState } from 'react';
import { connect } from 'react-redux';
import block from 'bem-css-modules';

import Link from 'components/common/Link';
import Table from 'components/common/Table';
import Table, { styles } from 'components/common/Table';
import Clickable from 'components/common/Clickable';
import ExternalLink from 'components/common/ExternalLink';
import withAdmin from 'components/hoc/withAdmin';
Expand All @@ -18,14 +19,16 @@ import { getArticleBaseUrl } from 'utils/fibery';
import { ROUTES_NAMES } from 'routes';
import { DATETIME_FORMAT } from 'constants';

const b = block(styles);

const mapStateToProps = (state, { lang }) => ({
articles: adminArticlesSelectors.getAll(state, lang),
});

const ARTICLE_COLS = [
{
id: 'title',
className: 'wir-table--font-large',
className: b('font', { size: 'large' }),
render: ({ value, row: { slug } }) => (
<Link route={ROUTES_NAMES.article} params={{ slug }}>
{value}
Expand All @@ -35,7 +38,7 @@ const ARTICLE_COLS = [
},
{
id: 'actions',
className: 'wir-table__column-actions',
className: b('column-actions'),
render: ({ row: { fiberyPublicId }, index }) => {
const url = getArticleBaseUrl(fiberyPublicId);
return (
Expand All @@ -61,13 +64,13 @@ const ARTICLE_COLS = [
},
{
id: 'subtitle',
className: 'wir-table--font-small',
className: b('font', { size: 'small' }),
formatter: text => `${text.slice(0, 100)}...`,
},
{
id: 'tagsByTopic',
title: 'Tags',
className: 'wir-table--font-small',
className: b('font', { size: 'small' }),
formatter: tagsByTopic => {
const tags = Object.values(tagsByTopic).reduce((acc, cur) => acc.concat(cur), []);
return renderNodeList(
Expand Down Expand Up @@ -106,7 +109,6 @@ const AdminArticlesPage = ({ articles }) => {
/>{' '}
{previewUrl && (
<Link
className="button"
route={ROUTES_NAMES.admin.preview}
params={{ url: encodeURIComponent(previewUrl) }}
target="_blank"
Expand All @@ -116,7 +118,7 @@ const AdminArticlesPage = ({ articles }) => {
)}
</div>
<br />
<Table rows={articles} cols={ARTICLE_COLS} />
<Table className={b()} rows={articles} cols={ARTICLE_COLS} />
</div>
);
};
Expand Down
9 changes: 6 additions & 3 deletions pages/admin/login.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import 'styles/pages/login.scss';
import styles from 'styles/pages/login.module.scss';

import React from 'react';
import PropTypes from 'prop-types';
import { ROUTES_NAMES } from 'routes';
import { connect } from 'react-redux';
import block from 'bem-css-modules';

import Redirect from 'components/common/Redirect';
import LoginForm from 'components/auth/LoginForm';

import { authSelectors } from 'redux/ducks/auth';
import { UserShape } from 'utils/customPropTypes';

const b = block(styles);

const mapStateToProps = state => ({
user: authSelectors.getUser(state),
});
Expand All @@ -21,8 +24,8 @@ const LoginPage = ({ user, routerQuery: { next = ROUTES_NAMES.admin.articles } }
}

return (
<div className="login-page-container">
<div className="login-page-wrap">
<div className={b('container')}>
<div className={b('wrap')}>
<LoginForm />
</div>
</div>
Expand Down

0 comments on commit e86d149

Please sign in to comment.