
* Use generated hooks in apps * Remove unused files * Use proper types in apps * Use generated hooks in attributes * Use generated hooks in auth module * Use generated hooks in categories * Use generated hooks in channels * Use generated types in collections * Remove legacy types from background tasks * Use generated hooks in customers * Use generated hooks in discounts * Use generated hook in file upload * Use generated types in gift cards * Use generated types in home * Use generated hooks in navigation * Use generated hooks in orders * Use generated hooks in pages * Use generated hooks in page types * Use generated hooks in permission groups * Use generated hooks in plugins * Use generated hooks in products * Use fragment to mark product variants * Improve code a bit * Use generated hooks in page types * Use generated types in searches * Use generated hooks in shipping * Use generated hooks in site settings * Use generated hooks in staff members * Use generated hooks in taxes * Place all gql generated files in one directory * Use generated hooks in translations * Use global types from new generated module * Use generated hooks in warehouses * Use generated hooks in webhooks * Use generated fragment types * Unclutter types * Remove hoc components * Split hooks and types * Fetch introspection file * Delete obsolete schema file * Fix rebase artifacts * Fix autoreplace * Fix auth provider tests * Fix urls * Remove leftover types * Fix rebase artifacts
124 lines
3.3 KiB
TypeScript
124 lines
3.3 KiB
TypeScript
import {
|
|
LanguageCodeEnum,
|
|
useUpdateVoucherTranslationsMutation,
|
|
useVoucherTranslationDetailsQuery
|
|
} from "@saleor/graphql";
|
|
import useNavigator from "@saleor/hooks/useNavigator";
|
|
import useNotifier from "@saleor/hooks/useNotifier";
|
|
import useShop from "@saleor/hooks/useShop";
|
|
import { commonMessages } from "@saleor/intl";
|
|
import { stringifyQs } from "@saleor/utils/urls";
|
|
import React from "react";
|
|
import { useIntl } from "react-intl";
|
|
|
|
import { extractMutationErrors, maybe } from "../../misc";
|
|
import TranslationsVouchersPage from "../components/TranslationsVouchersPage";
|
|
import { TranslationField, TranslationInputFieldName } from "../types";
|
|
import {
|
|
languageEntitiesUrl,
|
|
languageEntityUrl,
|
|
TranslatableEntities
|
|
} from "../urls";
|
|
import { getParsedTranslationInputData } from "../utils";
|
|
|
|
export interface TranslationsVouchersQueryParams {
|
|
activeField: string;
|
|
}
|
|
export interface TranslationsVouchersProps {
|
|
id: string;
|
|
languageCode: LanguageCodeEnum;
|
|
params: TranslationsVouchersQueryParams;
|
|
}
|
|
|
|
const TranslationsVouchers: React.FC<TranslationsVouchersProps> = ({
|
|
id,
|
|
languageCode,
|
|
params
|
|
}) => {
|
|
const navigate = useNavigator();
|
|
const notify = useNotifier();
|
|
const shop = useShop();
|
|
const intl = useIntl();
|
|
|
|
const voucherTranslations = useVoucherTranslationDetailsQuery({
|
|
variables: { id, language: languageCode }
|
|
});
|
|
|
|
const [
|
|
updateTranslations,
|
|
updateTranslationsOpts
|
|
] = useUpdateVoucherTranslationsMutation({
|
|
onCompleted: data => {
|
|
if (data.voucherTranslate.errors.length === 0) {
|
|
voucherTranslations.refetch();
|
|
notify({
|
|
status: "success",
|
|
text: intl.formatMessage(commonMessages.savedChanges)
|
|
});
|
|
navigate("?", { replace: true });
|
|
}
|
|
}
|
|
});
|
|
|
|
const onEdit = (field: string) =>
|
|
navigate(
|
|
"?" +
|
|
stringifyQs({
|
|
activeField: field
|
|
}),
|
|
{ replace: true }
|
|
);
|
|
|
|
const onDiscard = () => {
|
|
navigate("?", { replace: true });
|
|
};
|
|
|
|
const handleSubmit = (
|
|
{ name: fieldName }: TranslationField<TranslationInputFieldName>,
|
|
data: string
|
|
) =>
|
|
extractMutationErrors(
|
|
updateTranslations({
|
|
variables: {
|
|
id,
|
|
input: getParsedTranslationInputData({
|
|
data,
|
|
fieldName
|
|
}),
|
|
language: languageCode
|
|
}
|
|
})
|
|
);
|
|
|
|
const translation = voucherTranslations?.data?.translation;
|
|
|
|
return (
|
|
<TranslationsVouchersPage
|
|
activeField={params.activeField}
|
|
disabled={voucherTranslations.loading || updateTranslationsOpts.loading}
|
|
languages={maybe(() => shop.languages, [])}
|
|
languageCode={languageCode}
|
|
saveButtonState={updateTranslationsOpts.status}
|
|
onBack={() =>
|
|
navigate(
|
|
languageEntitiesUrl(languageCode, {
|
|
tab: TranslatableEntities.vouchers
|
|
})
|
|
)
|
|
}
|
|
onEdit={onEdit}
|
|
onDiscard={onDiscard}
|
|
onLanguageChange={lang =>
|
|
navigate(languageEntityUrl(lang, TranslatableEntities.vouchers, id))
|
|
}
|
|
onSubmit={handleSubmit}
|
|
data={
|
|
translation?.__typename === "VoucherTranslatableContent"
|
|
? translation
|
|
: null
|
|
}
|
|
/>
|
|
);
|
|
};
|
|
TranslationsVouchers.displayName = "TranslationsVouchers";
|
|
export default TranslationsVouchers;
|