Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix EditUser from redux changes #420

Merged
merged 3 commits into from
Dec 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions src/components/RFFComponents.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const sharedPropTypes = {
className: PropTypes.string,
label: PropTypes.string,
validate: PropTypes.func,
disabled: PropTypes.bool,
input: PropTypes.shape({
name: PropTypes.string,
value: PropTypes.any,
Expand All @@ -47,7 +48,7 @@ RFFCFormFeedback.propTypes = {
}),
}

export const RFFCFormCheck = ({ name, label, className = 'mb-3', validate }) => {
export const RFFCFormCheck = ({ name, label, className = 'mb-3', validate, disabled = false }) => {
return (
<Field name={name} type="checkbox" validate={validate}>
{({ input, meta }) => (
Expand All @@ -57,6 +58,7 @@ export const RFFCFormCheck = ({ name, label, className = 'mb-3', validate }) =>
// @todo revisit this, only shows green when checked
valid={!meta.error && meta.touched && validate}
invalid={meta.error && meta.touched && validate}
disabled={disabled}
id={name}
label={label}
/>
Expand All @@ -71,7 +73,7 @@ RFFCFormCheck.propTypes = {
...sharedPropTypes,
}

export const RFFCFormSwitch = ({ name, label, className = 'mb-3', validate }) => {
export const RFFCFormSwitch = ({ name, label, className = 'mb-3', validate, disabled = false }) => {
return (
<Field name={name} type="checkbox" validate={validate}>
{({ meta, input }) => (
Expand All @@ -81,6 +83,7 @@ export const RFFCFormSwitch = ({ name, label, className = 'mb-3', validate }) =>
// @todo revisit this, only shows green when checked
valid={!meta.error && meta.touched && validate}
invalid={meta.error && meta.touched && validate}
disabled={disabled}
id={name}
label={label}
/>
Expand All @@ -102,6 +105,7 @@ export const RFFCFormInput = ({
placeholder,
className = 'mb-3',
validate,
disabled = false,
}) => {
return (
<Field name={name} validate={validate}>
Expand All @@ -115,6 +119,7 @@ export const RFFCFormInput = ({
invalid={meta.error && meta.touched}
type={type}
id={name}
disabled={disabled}
area-describedby={name}
placeholder={placeholder}
/>
Expand All @@ -131,7 +136,14 @@ RFFCFormInput.propTypes = {
placeholder: PropTypes.string,
}

export const RFFCFormRadio = ({ name, label, value, className = 'mb-3', validate }) => {
export const RFFCFormRadio = ({
name,
label,
value,
className = 'mb-3',
validate,
disabled = false,
}) => {
return (
<Field name={name} type="radio" value={value} validate={validate}>
{({ meta, input }) => (
Expand All @@ -140,6 +152,7 @@ export const RFFCFormRadio = ({ name, label, value, className = 'mb-3', validate
{...input}
valid={!meta.error && meta.touched}
invalid={meta.error && meta.touched}
disabled={disabled}
type="radio"
name={name}
label={label}
Expand All @@ -162,6 +175,7 @@ export const RFFCFormTextarea = ({
placeholder,
className = 'mb-3',
validate,
disabled = false,
}) => {
return (
<Field name={name} type="radio" value={value} validate={validate}>
Expand All @@ -173,6 +187,7 @@ export const RFFCFormTextarea = ({
{...input}
valid={!meta.error && meta.touched}
invalid={meta.error && meta.touched}
disabled={disabled}
id={name}
placeholder={placeholder}
/>
Expand All @@ -196,6 +211,7 @@ export const RFFCFormSelect = ({
placeholder,
className = 'mb-3',
validate,
disabled = false,
}) => {
// handler for ignoring the first element ('the placeholder')
const selectValidate = (value, allValues, meta) => {
Expand All @@ -216,6 +232,7 @@ export const RFFCFormSelect = ({
{...input}
valid={!meta.error && meta.touched}
invalid={meta.error && meta.touched}
disabled={disabled}
>
<option value={placeholder}>{placeholder}</option>
{values.map(({ label, value }, idx) => (
Expand Down Expand Up @@ -267,7 +284,14 @@ const RFFSelectSearchClasses = {
'has-focus': 'select-search.has-focus',
}

export const RFFSelectSearch = ({ name, label, values = [], placeholder, validate }) => {
export const RFFSelectSearch = ({
name,
label,
values = [],
placeholder,
validate,
disabled = false,
}) => {
return (
<Field name={name} validate={validate}>
{({ meta, input }) => {
Expand All @@ -290,6 +314,7 @@ export const RFFSelectSearch = ({ name, label, values = [], placeholder, validat
}
return RFFSelectSearchClasses[key]
}}
disabled={disabled}
name={name}
options={values}
filterOptions={fuzzySearch}
Expand Down
14 changes: 10 additions & 4 deletions src/store/modules/domains.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ const initialState = {
},
}

const DOMAINS_LOAD = 'users/DOMAINS_LOAD'
const DOMAINS_LOAD_SUCCESS = 'users/DOMAINS_LOAD_SUCCESS'
const DOMAINS_LOAD_FAIL = 'users/DOMAINS_LOAD_FAIL'
const DOMAINS_LOAD = 'domains/DOMAINS_LOAD'
const DOMAINS_LOAD_SUCCESS = 'domains/DOMAINS_LOAD_SUCCESS'
const DOMAINS_LOAD_FAIL = 'domains/DOMAINS_LOAD_FAIL'

export default function reducer(state = initialState, action = {}) {
switch (action.type) {
Expand Down Expand Up @@ -48,6 +48,12 @@ export function listDomains({ tenantDomain }) {
promise: (client) =>
client
.get('/api/ListDomains', { params: { tenantFilter: tenantDomain } })
.then((result) => result.data),
.then((result) => result.data)
.then((result) => {
if (Array.isArray(result)) {
return result
}
return []
}),
}
}
8 changes: 7 additions & 1 deletion src/store/modules/licenses.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ export function listLicenses({ tenantDomain }) {
promise: (client) =>
client
.get('/api/ListLicenses', { params: { tenantFilter: tenantDomain } })
.then((result) => result.data),
.then((result) => result.data)
.then((result) => {
if (Array.isArray(result)) {
return result
}
return []
}),
}
}
58 changes: 34 additions & 24 deletions src/store/modules/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,31 +175,41 @@ export function listUser({ tenantDomain, userId }) {
dispatch({
types: [USER_LOAD, USER_LOAD_SUCCESS, USER_LOAD_FAIL],
hideToastError: true,
promise: (client) =>
client
.get('/api/ListUsers', { params: { TenantFilter: tenantDomain, userId } })
.then((result) => {
if (result.data && result.data.length > 0) {
return result.data[0]
}
dispatch(setModalContent({ body: 'Error loading user', title: 'User Not Found' }))
dispatch(showModal())
promise: async (client) => {
try {
const result = await client.get('/api/ListUsers', {
params: { TenantFilter: tenantDomain, userId },
})
.catch((error) => {
dispatch(
setModalContent({
body: (
<div>
Error loading user
<br />
<pre>{JSON.stringify(error, null, 2)}</pre>
</div>
),
title: 'User Not Found',
}),
)
dispatch(showModal())
}),

if (result.data && result.data.length > 0) {
return result.data[0]
}

dispatch(setModalContent({ body: 'Error loading user', title: 'User Not Found' }))
dispatch(showModal())
dispatch({
type: USER_LOAD_FAIL,
hideToastError: true,
error: new Error('User not found'),
})
return {}
} catch (error) {
dispatch(
setModalContent({
body: (
<div>
Error loading user
<br />
<pre>{JSON.stringify(error, null, 2)}</pre>
</div>
),
title: 'User Not Found',
}),
)
dispatch(showModal())
return error
}
},
})
}

Expand Down
Loading