Skip to content

Instantly share code, notes, and snippets.

View kettanaito's full-sized avatar
🚀
Extremely busy. Open source activity paused.

Artem Zakharchenko kettanaito

🚀
Extremely busy. Open source activity paused.
View GitHub Profile
@kettanaito
kettanaito / RegistrationForm.jsx
Created March 26, 2018 09:20
React Advanced Form - Skipping a field
<Input
name="confirmPassword"
type="password"
required
skip />
@kettanaito
kettanaito / RegistrationForm.jsx
Last active April 22, 2018 10:44
React Advanced Form - Reactive props
<Input
name="firstName"
required={({ get }) => {
// resolves any time "value" prop of "lastName" changes
return !!get(['lastName', 'value']);
}} />
<Input
name="lastName"
required={({ get }) => {
@kettanaito
kettanaito / validation-messages.js
Last active February 11, 2019 21:28
React Advanced Form - Validation messages (async)
// src/validation-messages.js
export default {
...
name: {
userEmail: {
async: ({ value, errorCode }) => {
return`E-mail "${email}" is already registered. Error code: ${errorCode}.`;
}
}
@kettanaito
kettanaito / RegistrationForm.jsx
Last active April 3, 2018 13:18
React Advanced Form - Async validation
import React from 'react';
import { Form } from 'react-advanced-form';
export default class RegistrationForm extends React.Component {
validateEmail = ({ value, fieldProps, fields, form }) => {
return fetch('https://backend/', { body: value })
.then(res => res.json())
.then((res) => {
return {
/* Determine if the e-mail is valid based on response */
@kettanaito
kettanaito / Cart.jsx
Last active March 28, 2018 15:12
React motion issue
import React from 'react';
import PropTypes from 'prop-types';
import { Helmet } from 'react-helmet';
import { connect } from 'react-redux';
import { addItem, removeItem } from '@state/cart/actions';
import { getTotalPrice } from '@state/cart/selectors';
import { Grid, Box, Button } from '@client/components';
/* Components */
import CartItemsList from './components/CartItemsList';
@kettanaito
kettanaito / RegistrationForm.jsx
Last active April 3, 2018 13:18
React Advanced Form - Submit
import React from 'react';
import { Form } from 'react-advanced-form';
import { Input } from '...';
export default class RegistrationForm extends React.Component {
registerUser = ({ serialized, fields, form }) => {
return fetch('https://backend.dev/user', {
method: 'POST',
body: JSON.stringify(serialized)
});
@kettanaito
kettanaito / arrayWithNumbers.js
Last active January 7, 2019 12:38
Useful utility functions I've come up with, found or seen during my career.
/**
* Accepts a number and returns an Array filled with numbers
* starting from 1 and up to the given number.
* @example
* arrayWithNumbers(5)
* // [1, 2, 3, 4, 5]
*/
export default function arrayWithNumbers(number) {
return Array(number).fill().map((_, i) => i + 1)
}
@kettanaito
kettanaito / validation-rules-analyzis.js
Created April 22, 2018 09:34
RAF - Rules analyzis
{
type: {
email: ({ value }) => isEmail(value)
}
}
@kettanaito
kettanaito / validation-rules-analyzis.js
Created April 22, 2018 09:36
RAF - Rules analyzis
{
type: {
password: {
capitalLetter: ({ value }) => /[A-Z]/.test(value),
oneNumber: ({ value }) => /[0-9]/.test(value),
minLength: ({ value }) => (value.length > 5)
}
}
}
@kettanaito
kettanaito / validation-rules-analyzis.js
Created April 22, 2018 09:41
RAF - Rules analyzis
{
name: {
confirmPassword: {
matches: ({ value, get }) => {
return (value === get(['userPassword', 'value']);
}
}
}
}