fixes field-type null values on validate, adds locale to data retrieval for edit / archive:
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import Cookies from 'universal-cookie';
|
||||
import superagentPromise from 'superagent-promise';
|
||||
import _superagent from 'superagent';
|
||||
import qs from 'qs';
|
||||
|
||||
const cookies = new Cookies();
|
||||
const superagent = superagentPromise(_superagent, global.Promise);
|
||||
@@ -12,8 +13,10 @@ const setJwt = () => {
|
||||
}
|
||||
|
||||
const requests = {
|
||||
get: url =>
|
||||
superagent.get(`${url}`).set(setJwt()).then(responseBody),
|
||||
get: (url, params) => {
|
||||
const query = qs.stringify(params, { addQueryPrefix: true });
|
||||
return superagent.get(`${url}${query}`).set(setJwt()).then(responseBody);
|
||||
},
|
||||
|
||||
post: (url, body) =>
|
||||
superagent.post(`${url}`, body).set(setJwt()).then(responseBody),
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
import React, { Component } from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import api from 'payload/api';
|
||||
|
||||
const mapState = state => ({
|
||||
locale: state.common.locale
|
||||
})
|
||||
|
||||
const withArchiveData = PassedComponent => {
|
||||
|
||||
class ArchiveData extends Component {
|
||||
@@ -13,19 +18,33 @@ const withArchiveData = PassedComponent => {
|
||||
}
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
api.requests.get(`${this.props.config.serverUrl}/${this.props.collection.slug}`).then(
|
||||
fetchData = () => {
|
||||
const params = {
|
||||
lang: this.props.locale
|
||||
};
|
||||
|
||||
api.requests.get(`${this.props.config.serverUrl}/${this.props.collection.slug}`, params).then(
|
||||
res => this.setState({ data: res }),
|
||||
err => console.warn(err)
|
||||
)
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.fetchData();
|
||||
}
|
||||
|
||||
componentDidUpdate(prevProps) {
|
||||
if (prevProps.locale !== this.props.locale) {
|
||||
this.fetchData();
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
return <PassedComponent {...this.props} data={this.state.data} />;
|
||||
}
|
||||
}
|
||||
|
||||
return ArchiveData;
|
||||
return connect(mapState)(ArchiveData);
|
||||
}
|
||||
|
||||
export default withArchiveData;
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
import React, { Component } from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import { withRouter } from 'react-router-dom';
|
||||
import api from 'payload/api';
|
||||
|
||||
const mapState = state => ({
|
||||
locale: state.common.locale
|
||||
})
|
||||
|
||||
const withEditData = PassedComponent => {
|
||||
|
||||
class EditData extends Component {
|
||||
@@ -13,11 +18,14 @@ const withEditData = PassedComponent => {
|
||||
}
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
fetchData = () => {
|
||||
const slug = this.props.match.params.slug;
|
||||
const params = {
|
||||
lang: this.props.locale
|
||||
};
|
||||
|
||||
if (slug) {
|
||||
api.requests.get(`${this.props.config.serverUrl}/${this.props.collection.slug}/${slug}`).then(
|
||||
api.requests.get(`${this.props.config.serverUrl}/${this.props.collection.slug}/${slug}`, params).then(
|
||||
res => this.setState({ data: res }),
|
||||
err => {
|
||||
console.warn(err);
|
||||
@@ -27,12 +35,22 @@ const withEditData = PassedComponent => {
|
||||
}
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.fetchData();
|
||||
}
|
||||
|
||||
componentDidUpdate(prevProps) {
|
||||
if (prevProps.locale !== this.props.locale) {
|
||||
this.fetchData();
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
return <PassedComponent {...this.props} data={this.state.data } />;
|
||||
return <PassedComponent {...this.props} data={this.state.data} />;
|
||||
}
|
||||
}
|
||||
|
||||
return withRouter(EditData);
|
||||
return withRouter(connect(mapState)(EditData));
|
||||
}
|
||||
|
||||
export default withEditData;
|
||||
|
||||
@@ -16,7 +16,7 @@ const Email = props => {
|
||||
{props.error}
|
||||
{props.label}
|
||||
<input
|
||||
value={props.value}
|
||||
value={props.value || ''}
|
||||
onChange={props.onChange}
|
||||
disabled={props.disabled}
|
||||
placeholder={props.placeholder}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import React from 'react';
|
||||
import { fieldType } from 'payload/components';
|
||||
|
||||
const HiddenInput = props => <input type="hidden" value={props.value}
|
||||
const HiddenInput = props => <input type="hidden" value={props.value || ''}
|
||||
onChange={props.onChange} id={props.id ? props.id : props.name} name={props.name} />;
|
||||
|
||||
export default fieldType(HiddenInput, 'hiddenInput');
|
||||
|
||||
@@ -16,7 +16,7 @@ const Input = props => {
|
||||
{props.error}
|
||||
{props.label}
|
||||
<input
|
||||
value={props.value}
|
||||
value={props.value || ''}
|
||||
onChange={props.onChange}
|
||||
disabled={props.disabled}
|
||||
placeholder={props.placeholder}
|
||||
|
||||
@@ -19,7 +19,7 @@ const Password = props => {
|
||||
{props.error}
|
||||
{props.label}
|
||||
<input
|
||||
value={props.value}
|
||||
value={props.value || ''}
|
||||
onChange={props.onChange}
|
||||
disabled={props.disabled}
|
||||
placeholder={props.placeholder}
|
||||
|
||||
@@ -13,7 +13,7 @@ const Textarea = props => {
|
||||
{props.error}
|
||||
{props.label}
|
||||
<textarea
|
||||
value={ props.value }
|
||||
value={props.value || ''}
|
||||
onChange={props.onChange}
|
||||
disabled={props.disabled}
|
||||
placeholder={props.placeholder}
|
||||
|
||||
@@ -20,7 +20,7 @@ const fieldType = (PassedComponent, type, validate, errors) => {
|
||||
name: this.props.name,
|
||||
value: value,
|
||||
valid: this.props.required && validate
|
||||
? validate(value, this.props.type)
|
||||
? validate(value || '', this.props.type)
|
||||
: true
|
||||
});
|
||||
}
|
||||
@@ -48,8 +48,8 @@ const fieldType = (PassedComponent, type, validate, errors) => {
|
||||
|
||||
render() {
|
||||
const valid = this.props.context.fields[this.props.name]
|
||||
? this.props.context.fields[this.props.name].valid
|
||||
: true;
|
||||
? this.props.context.fields[this.props.name].valid
|
||||
: true;
|
||||
|
||||
const showError = valid === false && this.props.context.submitted;
|
||||
|
||||
@@ -62,14 +62,14 @@ const fieldType = (PassedComponent, type, validate, errors) => {
|
||||
|
||||
return (
|
||||
<PassedComponent {...this.props}
|
||||
className={className}
|
||||
value={value}
|
||||
label={<Label {...this.props} />}
|
||||
error={<Error showError={showError} type={this.props.type} />}
|
||||
onChange={e => {
|
||||
this.sendField(e.target.value);
|
||||
this.props.onChange && this.props.onChange(e);
|
||||
}} />
|
||||
className={className}
|
||||
value={value}
|
||||
label={<Label {...this.props} />}
|
||||
error={<Error showError={showError} type={this.props.type} />}
|
||||
onChange={e => {
|
||||
this.sendField(e.target.value);
|
||||
this.props.onChange && this.props.onChange(e);
|
||||
}} />
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,12 +12,16 @@ const mapState = state => ({
|
||||
const Localizer = props => {
|
||||
const { languages } = props.config.localization;
|
||||
|
||||
if (languages.length <= 1) return null;
|
||||
|
||||
return (
|
||||
<div className="localizer">
|
||||
<span>{props.locale}</span>
|
||||
<ul>
|
||||
{languages.map((lang, i) => {
|
||||
|
||||
if (lang === props.locale) return null;
|
||||
|
||||
const newParams = {
|
||||
...props.searchParams,
|
||||
lang: lang
|
||||
|
||||
@@ -67,7 +67,6 @@ export default (state = defaultState, action) => {
|
||||
};
|
||||
|
||||
case 'SET_LOCALE':
|
||||
console.log(action.payload);
|
||||
return {
|
||||
...state,
|
||||
locale: action.payload
|
||||
|
||||
Reference in New Issue
Block a user