Skip to content

Commit

Permalink
fix requisitions too
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-prins committed Dec 30, 2024
1 parent 3c4586e commit e6a4d66
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ const InputWithLabel = ({
const errorHandler = useCallback(
(res: any) => {
// probably shouldn't be any, but UpdateIndicatorValue doesn't have res.error.__typename
if (res?.__typename === 'UpdateIndicatorValueError') {
if (res?.error?.__typename === 'RecordNotFound') {
if (res.__typename === 'UpdateIndicatorValueError') {
if (res.error?.__typename === 'RecordNotFound') {
error(t('messages.record-not-found'))();
} else {
error(t('error.value-type-not-correct'))();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const IndicatorEditPage = () => {
},
[2, 3]
);
}, [programIndicatorLineId]);
}, [programIndicatorLineId, programIndicators]);

if (isLoading || isProgramIndicatorsLoading) {
return <BasicSpinner />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ const INPUT_WIDTH = 185;
const LABEL_WIDTH = '150px';

const InputWithLabel = ({
autoFocus,
data,
disabled,
}: {
autoFocus: boolean;
data: IndicatorColumnNode;
disabled: boolean;
}) => {
Expand All @@ -56,6 +58,12 @@ const InputWithLabel = ({
},
[t]
);

const sharedProps = {
disabled,
autoFocus,
};

const inputComponent =
data.valueType === IndicatorValueTypeNode.Number ? (
<NumericTextInput
Expand All @@ -65,8 +73,7 @@ const InputWithLabel = ({
const newValue = isNaN(Number(v)) ? 0 : v;
update({ value: String(newValue) }).then(errorHandler);
}}
disabled={disabled}
autoFocus
{...sharedProps}
/>
) : (
<BasicTextInput
Expand All @@ -75,8 +82,7 @@ const InputWithLabel = ({
onChange={e => {
update({ value: e.target.value }).then(errorHandler);
}}
disabled={disabled}
autoFocus
{...sharedProps}
/>
);

Expand Down Expand Up @@ -106,9 +112,14 @@ export const IndicatorLineEdit = ({
return (
<>
<Box display="flex" flexDirection="column">
{columns?.map(c => {
{columns?.map((c, i) => {
return (
<InputWithLabel key={c.value?.id} data={c} disabled={disabled} />
<InputWithLabel
key={c.value?.id}
data={c}
disabled={disabled}
autoFocus={i === 0}
/>
);
})}
</Box>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState } from 'react';
import { useResponse } from '../../api';
import { useDebounceCallback } from '@common/hooks';
import { useDebounceCallback, useNotification } from '@common/hooks';
import {
IndicatorLineRowFragment,
IndicatorValueFragment,
Expand Down Expand Up @@ -44,10 +44,12 @@ export const useDraftIndicatorValue = (
) => {
const { mutateAsync, isLoading } =
useResponse.document.updateIndicatorValue();
const { error } = useNotification();

const [draft, setDraft] = useState<IndicatorValueFragment>(indicatorValue);
const save = useDebounceCallback(
(patch: Partial<IndicatorValueFragment>) =>
mutateAsync({ ...draft, ...patch }),
mutateAsync({ ...draft, ...patch }).catch(e => error(e.message)()),
[],
500
);
Expand Down
10 changes: 7 additions & 3 deletions client/packages/requisitions/src/ResponseRequisition/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,16 @@ export const getResponseQueries = (sdk: Sdk, storeId: string) => ({
const result = await sdk.customerProgramSettings({ storeId });
return result.customerProgramRequisitionSettings;
},
getIndicators: async (customerNameLinkId: string, periodId: string, programId: string) => {
getIndicators: async (
customerNameLinkId: string,
periodId: string,
programId: string
) => {
let result = await sdk.programIndicators({
storeId,
customerNameLinkId,
periodId,
programId
programId,
});

if (result?.programIndicators.__typename === 'ProgramIndicatorConnector') {
Expand All @@ -321,7 +325,7 @@ export const getResponseQueries = (sdk: Sdk, storeId: string) => ({
},
updateIndicatorValue: async (patch: UpdateIndicatorValueInput) => {
let result = await sdk.updateIndicatorValue({ storeId, input: patch });

if (!!result?.updateIndicatorValue) {
return result.updateIndicatorValue;
}
Expand Down

0 comments on commit e6a4d66

Please sign in to comment.