Skip to content

Commit

Permalink
fix: show out of credits error at machine translations and batch oper…
Browse files Browse the repository at this point in the history
…ations (#2830)
  • Loading branch information
stepan662 authored Jan 10, 2025
1 parent 6d20a7d commit 0eb095d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion webapp/src/views/projects/BaseProjectView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const BaseProjectView: React.FC<Props> = ({
{...otherProps}
navigation={[...prefixNavigation, ...(navigation || [])]}
navigationRight={
<Box display="grid">
<Box display="grid" gridAutoFlow="column" gap={1}>
<BatchOperationsSummary />
<Usage />
</Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { useBatchOperationTypeTranslate } from 'tg.translationTools/useBatchOper
import { useOperationCancel } from './useOperationCancel';
import LoadingButton from 'tg.component/common/form/LoadingButton';
import { useLoadingRegister } from 'tg.component/GlobalLoading';
import { useGlobalActions } from 'tg.globalContext/GlobalContext';

type Props = {
operation: BatchJobModel;
Expand All @@ -36,6 +37,7 @@ export const BatchOperationDialog = ({
}: Props) => {
const { t } = useTranslate();
const project = useProject();
const { incrementPlanLimitErrors } = useGlobalActions();

const liveBatch = useProjectContext((c) =>
c.batchOperations?.find((o) => o.id === operation.id)
Expand Down Expand Up @@ -72,6 +74,12 @@ export const BatchOperationDialog = ({
}
}, [isFinished]);

useEffect(() => {
if (data.errorMessage === 'out_of_credits') {
incrementPlanLimitErrors();
}
}, [data.errorMessage]);

return (
<Dialog open>
<DialogTitle sx={{ width: 'min(80vw, 400px)' }}>{typeLabel}</DialogTitle>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useMTStreamed } from './useMTStreamed';
import { TabMessage } from '../../common/TabMessage';
import { PanelContentProps } from '../../common/types';
import { MachineTranslationItem } from './MachineTranslationItem';
import { useGlobalActions } from 'tg.globalContext/GlobalContext';

const StyledContainer = styled('div')`
display: flex;
Expand Down Expand Up @@ -41,6 +42,7 @@ export const MachineTranslation: React.FC<PanelContentProps> = ({
activeVariant,
}) => {
const { t } = useTranslate();
const { incrementPlanLimitErrors } = useGlobalActions();

const deps = {
keyId: keyData.keyId,
Expand Down Expand Up @@ -81,6 +83,12 @@ export const MachineTranslation: React.FC<PanelContentProps> = ({
Boolean(arrayResults.length);
const contextPresent = keyData.contextPresent;

useEffect(() => {
if (outOfCredit) {
incrementPlanLimitErrors();
}
}, [outOfCredit]);

useEffect(() => {
setItemsCount(arrayResults.length);
}, [arrayResults.length]);
Expand Down

0 comments on commit 0eb095d

Please sign in to comment.