saleor-dashboard/src/services/components/ServiceInfo/ServiceInfo.tsx

60 lines
1.5 KiB
TypeScript
Raw Normal View History

2019-09-26 15:33:44 +00:00
import Card from "@material-ui/core/Card";
import CardContent from "@material-ui/core/CardContent";
import TextField from "@material-ui/core/TextField";
import CardTitle from "@saleor/components/CardTitle";
import { AccountErrorFragment } from "@saleor/fragments/types/AccountErrorFragment";
import { FormChange } from "@saleor/hooks/useForm";
2020-03-11 09:55:14 +00:00
import { getFormErrors } from "@saleor/utils/errors";
import getAccountErrorMessage from "@saleor/utils/errors/account";
import React from "react";
import { useIntl } from "react-intl";
2019-09-26 15:33:44 +00:00
export interface ServiceInfoProps {
data: {
name: string;
};
disabled: boolean;
2020-03-11 09:55:14 +00:00
errors: AccountErrorFragment[];
2019-09-26 15:33:44 +00:00
onChange: FormChange;
}
2020-03-11 09:55:14 +00:00
const ServiceInfo: React.FC<ServiceInfoProps> = ({
data,
disabled,
errors,
onChange
}) => {
2019-09-26 15:33:44 +00:00
const intl = useIntl();
2020-03-11 09:55:14 +00:00
const formErrors = getFormErrors(["name"], errors);
2019-09-26 15:33:44 +00:00
return (
<Card>
<CardTitle
title={intl.formatMessage({
defaultMessage: "Service Account Information",
description: "header"
})}
/>
<CardContent>
<TextField
disabled={disabled}
2020-03-11 09:55:14 +00:00
error={!!formErrors.name}
2019-09-26 15:33:44 +00:00
label={intl.formatMessage({
defaultMessage: "Account Name",
description: "service account"
})}
2020-03-11 09:55:14 +00:00
helperText={getAccountErrorMessage(formErrors.name, intl)}
2019-09-26 15:33:44 +00:00
fullWidth
name="name"
value={data.name}
onChange={onChange}
/>
</CardContent>
</Card>
);
};
ServiceInfo.displayName = "ServiceInfo";
export default ServiceInfo;