Fix plugin auth section crash (#1951)
* Fix plugin auth section crash * Simplify code
This commit is contained in:
parent
d273706ef8
commit
40d9575cad
2 changed files with 35 additions and 44 deletions
|
@ -3,7 +3,6 @@ import CardTitle from "@saleor/components/CardTitle";
|
||||||
import Hr from "@saleor/components/Hr";
|
import Hr from "@saleor/components/Hr";
|
||||||
import {
|
import {
|
||||||
ConfigurationItemFragment,
|
ConfigurationItemFragment,
|
||||||
ConfigurationItemInput,
|
|
||||||
ConfigurationTypeFieldEnum
|
ConfigurationTypeFieldEnum
|
||||||
} from "@saleor/graphql";
|
} from "@saleor/graphql";
|
||||||
import { buttonMessages } from "@saleor/intl";
|
import { buttonMessages } from "@saleor/intl";
|
||||||
|
@ -13,7 +12,6 @@ import React from "react";
|
||||||
import { FormattedMessage, useIntl } from "react-intl";
|
import { FormattedMessage, useIntl } from "react-intl";
|
||||||
|
|
||||||
interface PluginAuthorizationProps {
|
interface PluginAuthorizationProps {
|
||||||
data: ConfigurationItemInput[];
|
|
||||||
fields: ConfigurationItemFragment[];
|
fields: ConfigurationItemFragment[];
|
||||||
onClear: (field: string) => void;
|
onClear: (field: string) => void;
|
||||||
onEdit: (field: string) => void;
|
onEdit: (field: string) => void;
|
||||||
|
@ -39,7 +37,7 @@ const useStyles = makeStyles(
|
||||||
);
|
);
|
||||||
|
|
||||||
const PluginAuthorization: React.FC<PluginAuthorizationProps> = props => {
|
const PluginAuthorization: React.FC<PluginAuthorizationProps> = props => {
|
||||||
const { data, fields, onClear, onEdit } = props;
|
const { fields, onClear, onEdit } = props;
|
||||||
|
|
||||||
const classes = useStyles(props);
|
const classes = useStyles(props);
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
|
@ -57,12 +55,7 @@ const PluginAuthorization: React.FC<PluginAuthorizationProps> = props => {
|
||||||
})}
|
})}
|
||||||
/>
|
/>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
{secretFields.map((field, fieldIndex) => {
|
{secretFields.map((field, fieldIndex) => (
|
||||||
const inputData = data.find(
|
|
||||||
dataField => dataField.name === field.name
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<React.Fragment key={field.name}>
|
<React.Fragment key={field.name}>
|
||||||
<div className={classes.item} key={field.name}>
|
<div className={classes.item} key={field.name}>
|
||||||
{field.type === ConfigurationTypeFieldEnum.SECRET ||
|
{field.type === ConfigurationTypeFieldEnum.SECRET ||
|
||||||
|
@ -70,7 +63,7 @@ const PluginAuthorization: React.FC<PluginAuthorizationProps> = props => {
|
||||||
<div>
|
<div>
|
||||||
<Typography variant="body1">{field.label}</Typography>
|
<Typography variant="body1">{field.label}</Typography>
|
||||||
{field.value !== null && (
|
{field.value !== null && (
|
||||||
<Typography>**** {inputData.value}</Typography>
|
<Typography>**** {field.value}</Typography>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
|
@ -102,8 +95,7 @@ const PluginAuthorization: React.FC<PluginAuthorizationProps> = props => {
|
||||||
<Hr className={classes.hr} />
|
<Hr className={classes.hr} />
|
||||||
)}
|
)}
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
);
|
))}
|
||||||
})}
|
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
);
|
);
|
||||||
|
|
|
@ -142,7 +142,6 @@ const PluginsDetailsPage: React.FC<PluginsDetailsPageProps> = ({
|
||||||
<>
|
<>
|
||||||
<CardSpacer />
|
<CardSpacer />
|
||||||
<PluginAuthorization
|
<PluginAuthorization
|
||||||
data={data.configuration}
|
|
||||||
fields={selectedConfig.configuration}
|
fields={selectedConfig.configuration}
|
||||||
onClear={onClear}
|
onClear={onClear}
|
||||||
onEdit={onEdit}
|
onEdit={onEdit}
|
||||||
|
|
Loading…
Reference in a new issue