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: {
|
||||
defaultMessage: "Properties"
|
||||
},
|
||||
readOnly: {
|
||||
defaultMessage: "Saleor runs in read-only mode. Changes not saved."
|
||||
},
|
||||
requiredField: {
|
||||
defaultMessage: "This field is required"
|
||||
},
|
||||
|
|
|
@ -6,6 +6,7 @@ import { useIntl } from "react-intl";
|
|||
|
||||
import useNotifier from "./hooks/useNotifier";
|
||||
import { commonMessages } from "./intl";
|
||||
import { maybe } from "./misc";
|
||||
|
||||
export interface TypedMutationInnerProps<TData, TVariables> {
|
||||
children: (
|
||||
|
@ -32,9 +33,21 @@ export function TypedMutation<TData, TVariables>(
|
|||
mutation={mutation}
|
||||
onCompleted={onCompleted}
|
||||
onError={(err: ApolloError) => {
|
||||
if (
|
||||
maybe(
|
||||
() =>
|
||||
err.graphQLErrors[0].extensions.exception.code ===
|
||||
"ReadOnlyException"
|
||||
)
|
||||
) {
|
||||
notify({
|
||||
text: intl.formatMessage(commonMessages.readOnly)
|
||||
});
|
||||
} else {
|
||||
notify({
|
||||
text: intl.formatMessage(commonMessages.somethingWentWrong)
|
||||
});
|
||||
}
|
||||
if (onError) {
|
||||
onError(err);
|
||||
}
|
||||
|
|
|
@ -82,7 +82,7 @@ export function TypedQuery<TData, TVariables>(
|
|||
skip={skip}
|
||||
context={{ useBatching: true }}
|
||||
>
|
||||
{queryData => {
|
||||
{(queryData: QueryResult<TData, TVariables>) => {
|
||||
if (queryData.error) {
|
||||
pushMessage({
|
||||
text: intl.formatMessage(commonMessages.somethingWentWrong)
|
||||
|
|
Loading…
Reference in a new issue