Handle readonly mode
This commit is contained in:
parent
759561634d
commit
23aaa2a091
3 changed files with 20 additions and 4 deletions
|
@ -47,6 +47,9 @@ export const commonMessages = defineMessages({
|
||||||
properties: {
|
properties: {
|
||||||
defaultMessage: "Properties"
|
defaultMessage: "Properties"
|
||||||
},
|
},
|
||||||
|
readOnly: {
|
||||||
|
defaultMessage: "Saleor runs in read-only mode. Changes not saved."
|
||||||
|
},
|
||||||
requiredField: {
|
requiredField: {
|
||||||
defaultMessage: "This field is required"
|
defaultMessage: "This field is required"
|
||||||
},
|
},
|
||||||
|
|
|
@ -6,6 +6,7 @@ import { useIntl } from "react-intl";
|
||||||
|
|
||||||
import useNotifier from "./hooks/useNotifier";
|
import useNotifier from "./hooks/useNotifier";
|
||||||
import { commonMessages } from "./intl";
|
import { commonMessages } from "./intl";
|
||||||
|
import { maybe } from "./misc";
|
||||||
|
|
||||||
export interface TypedMutationInnerProps<TData, TVariables> {
|
export interface TypedMutationInnerProps<TData, TVariables> {
|
||||||
children: (
|
children: (
|
||||||
|
@ -32,9 +33,21 @@ export function TypedMutation<TData, TVariables>(
|
||||||
mutation={mutation}
|
mutation={mutation}
|
||||||
onCompleted={onCompleted}
|
onCompleted={onCompleted}
|
||||||
onError={(err: ApolloError) => {
|
onError={(err: ApolloError) => {
|
||||||
|
if (
|
||||||
|
maybe(
|
||||||
|
() =>
|
||||||
|
err.graphQLErrors[0].extensions.exception.code ===
|
||||||
|
"ReadOnlyException"
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
notify({
|
||||||
|
text: intl.formatMessage(commonMessages.readOnly)
|
||||||
|
});
|
||||||
|
} else {
|
||||||
notify({
|
notify({
|
||||||
text: intl.formatMessage(commonMessages.somethingWentWrong)
|
text: intl.formatMessage(commonMessages.somethingWentWrong)
|
||||||
});
|
});
|
||||||
|
}
|
||||||
if (onError) {
|
if (onError) {
|
||||||
onError(err);
|
onError(err);
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,7 +82,7 @@ export function TypedQuery<TData, TVariables>(
|
||||||
skip={skip}
|
skip={skip}
|
||||||
context={{ useBatching: true }}
|
context={{ useBatching: true }}
|
||||||
>
|
>
|
||||||
{queryData => {
|
{(queryData: QueryResult<TData, TVariables>) => {
|
||||||
if (queryData.error) {
|
if (queryData.error) {
|
||||||
pushMessage({
|
pushMessage({
|
||||||
text: intl.formatMessage(commonMessages.somethingWentWrong)
|
text: intl.formatMessage(commonMessages.somethingWentWrong)
|
||||||
|
|
Loading…
Reference in a new issue