Skip to content

Commit

Permalink
Fix Prop 't' is undefined in UserEdit component
Browse files Browse the repository at this point in the history
Fixes: #843
  • Loading branch information
larixer committed Sep 10, 2018
1 parent 9cce311 commit 289e867
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { FontAwesome } from '@expo/vector-icons';
import { View, StyleSheet } from 'react-native';
import SelectStyles from '../styles/Select';

const Select = ({ icon, iconName, iconColor, iconSize, onValueChange, cols, selectedValue, value, ...props }) => {
const Select = ({ icon, iconName, iconColor, iconSize, onChange, cols, selectedValue, value, ...props }) => {
return (
<View style={styles.container}>
<View style={styles.pickerWrapper}>
<Picker
onChange={val => onValueChange(cols === 1 ? val[0] : val)}
onChange={val => onChange(cols === 1 ? val[0] : val)}
value={[selectedValue || value]}
cols={cols || 1}
{...props}
Expand All @@ -31,7 +31,7 @@ const Select = ({ icon, iconName, iconColor, iconSize, onValueChange, cols, sele
};

Select.propTypes = {
onValueChange: PropTypes.func,
onChange: PropTypes.func,
cols: PropTypes.number,
value: PropTypes.string,
selectedValue: PropTypes.string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ import React from 'react';
import { Switch as ADSwitch } from 'antd-mobile-rn';
import PropTypes from 'prop-types';

const Switch = ({ checked, value, onValueChange, onChange, ...props }) => {
return <ADSwitch checked={value || checked} onChange={onValueChange || onChange} {...props} />;
const Switch = ({ checked, value, onChange, ...props }) => {
return <ADSwitch checked={value || checked} {...props} />;
};

Switch.propTypes = {
checked: PropTypes.bool,
value: PropTypes.bool,
onValueChange: PropTypes.func,
onChange: PropTypes.func
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class PaginationDemo extends React.Component {
mode="dropdown"
data={options}
selectedValue={pagination}
onValueChange={this.onPaginationTypeChange}
onChange={this.onPaginationTypeChange}
okText={t('list.select.ok')}
dismissText={t('list.select.dismiss')}
cols={1}
Expand Down
4 changes: 2 additions & 2 deletions packages/client/src/modules/user/components/UserAddView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class UserAddView extends React.PureComponent {
<UserForm
onSubmit={this.props.onSubmit}
initialValues={{}}
shouldRoleDisplay={true}
shouldActiveDisplay={true}
shouldDisplayRole={true}
shouldDisplayActive={true}
/>
</View>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ class UserAddView extends React.PureComponent {
<UserForm
onSubmit={this.props.onSubmit}
initialValues={{}}
shouldRoleDisplay={true}
shouldActiveDisplay={true}
shouldDisplayRole={true}
shouldDisplayActive={true}
/>
</PageLayout>
);
Expand Down
4 changes: 2 additions & 2 deletions packages/client/src/modules/user/components/UserEditView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class UserEditView extends React.PureComponent {
<View style={styles.container}>
<UserForm
onSubmit={this.props.onSubmit}
shouldRoleDisplay={isNotSelf}
shouldActiveDisplay={isNotSelf}
shouldDisplayRole={isNotSelf}
shouldDisplayActive={isNotSelf}
initialValues={user || {}}
/>
</View>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ class UserEditView extends React.PureComponent {
</h2>
<UserForm
onSubmit={this.props.onSubmit}
shouldRoleDisplay={isNotSelf}
shouldActiveDisplay={isNotSelf}
shouldDisplayRole={isNotSelf}
shouldDisplayActive={isNotSelf}
initialValues={user}
/>
</PageLayout>
Expand Down
14 changes: 7 additions & 7 deletions packages/client/src/modules/user/components/UserForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const handleRoleChange = (type, value, setFieldValue) => {

const validate = values => validateForm(values, userFormSchema);

const UserForm = ({ values, handleSubmit, setFieldValue, t, shouldRoleDisplay, shouldActiveDisplay }) => {
const UserForm = ({ values, handleSubmit, setFieldValue, t, shouldDisplayRole, shouldDisplayActive }) => {
const options = [
{
value: 'user',
Expand Down Expand Up @@ -57,7 +57,7 @@ const UserForm = ({ values, handleSubmit, setFieldValue, t, shouldRoleDisplay, s
keyboardType="email-address"
placeholderTextColor={placeholderColor}
/>
{shouldRoleDisplay && (
{shouldDisplayRole && (
<Field
name="role"
component={RenderSelect}
Expand All @@ -66,16 +66,16 @@ const UserForm = ({ values, handleSubmit, setFieldValue, t, shouldRoleDisplay, s
dismissText={t('userEdit.select.dismissText')}
placeholderTextColor={placeholderColor}
selectedValue={role}
onValueChange={value => handleRoleChange('role', value, setFieldValue)}
onChange={value => handleRoleChange('role', value, setFieldValue)}
cols={1}
data={options}
/>
)}
{shouldActiveDisplay && (
{shouldDisplayActive && (
<Field
name="isActive"
label={t('userEdit.form.field.active')}
onValueChange={() => setFieldValue('isActive', !isActive)}
onChange={() => setFieldValue('isActive', !isActive)}
component={RenderSwitch}
placeholder={t('userEdit.form.field.active')}
checked={isActive}
Expand Down Expand Up @@ -146,8 +146,8 @@ UserForm.propTypes = {
setTouched: PropTypes.func,
isValid: PropTypes.bool,
error: PropTypes.string,
shouldRoleDisplay: PropTypes.bool,
shouldActiveDisplay: PropTypes.bool,
shouldDisplayRole: PropTypes.bool,
shouldDisplayActive: PropTypes.bool,
values: PropTypes.object,
errors: PropTypes.object,
initialValues: PropTypes.object.isRequired,
Expand Down
10 changes: 5 additions & 5 deletions packages/client/src/modules/user/components/UserForm.web.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const updateUserFormSchema = {

const validate = (values, createNew) => validateForm(values, createNew ? createUserFormSchema : updateUserFormSchema);

const UserForm = ({ values, handleSubmit, error, setFieldValue, t, shouldRoleDisplay, shouldActiveDisplay }) => {
const UserForm = ({ values, handleSubmit, error, setFieldValue, t, shouldDisplayRole, shouldDisplayActive }) => {
const { username, email, role, isActive, profile, auth, password, passwordConfirmation } = values;

return (
Expand All @@ -42,7 +42,7 @@ const UserForm = ({ values, handleSubmit, error, setFieldValue, t, shouldRoleDis
value={username}
/>
<Field name="email" component={RenderField} type="email" label={t('userEdit.form.field.email')} value={email} />
{shouldRoleDisplay && (
{shouldDisplayRole && (
<Field
name="role"
component={RenderSelect}
Expand All @@ -54,7 +54,7 @@ const UserForm = ({ values, handleSubmit, error, setFieldValue, t, shouldRoleDis
<Option value="admin">{t('userEdit.form.field.role.admin')}</Option>
</Field>
)}
{shouldActiveDisplay && (
{shouldDisplayActive && (
<Field
name="isActive"
component={RenderCheckBox}
Expand Down Expand Up @@ -118,8 +118,8 @@ UserForm.propTypes = {
onSubmit: PropTypes.func,
setTouched: PropTypes.func,
isValid: PropTypes.bool,
shouldRoleDisplay: PropTypes.bool,
shouldActiveDisplay: PropTypes.bool,
shouldDisplayRole: PropTypes.bool,
shouldDisplayActive: PropTypes.bool,
error: PropTypes.string,
values: PropTypes.object,
errors: PropTypes.object,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class UsersFilterView extends React.PureComponent {
mode="dropdown"
data={options}
selectedValue={role}
onValueChange={value => this.handleRole(value)}
onChange={value => this.handleRole(value)}
okText={t('users.select.okText')}
dismissText={t('users.select.dismissText')}
cols={1}
Expand All @@ -189,7 +189,7 @@ class UsersFilterView extends React.PureComponent {
<View style={styles.itemContainer}>
<Text style={styles.itemTitle}>{t('users.column.active')}</Text>
<View style={styles.itemAction}>
<Switch onValueChange={this.handleIsActive} value={isActive} />
<Switch onChange={this.handleIsActive} value={isActive} />
</View>
</View>
<TouchableOpacity style={styles.itemContainer} onPress={() => this.setState({ showModal: true })}>
Expand Down
2 changes: 2 additions & 0 deletions packages/client/src/modules/user/containers/UserEdit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import UserEditView from '../components/UserEditView';
import USER_QUERY from '../graphql/UserQuery.graphql';
import EDIT_USER from '../graphql/EditUser.graphql';
import settings from '../../../../../../settings';
import translate from '../../../i18n';
import UserFormatter from '../helpers/UserFormatter';

class UserEdit extends React.Component {
Expand Down Expand Up @@ -42,6 +43,7 @@ class UserEdit extends React.Component {
}

export default compose(
translate('user'),
graphql(USER_QUERY, {
options: props => {
let id = 0;
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/middleware/website.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const Html = ({ content, state, css, clientModules, helmet }: HtmlProps) => (

const renderServerSide = async (req: any, res: any) => {
const clientModules = require('../../../client/src/modules').default;
const schemaLink = new SchemaLink({ schema, context: await modules.createContext(req, res) });
const schemaLink = new SchemaLink({ schema, context: { ...(await modules.createContext(req, res)), req, res } });
const client = createApolloClient({
apiUrl,
createNetLink: !isApiExternal ? () => schemaLink : undefined,
Expand Down

0 comments on commit 289e867

Please sign in to comment.