Skip to content

Commit

Permalink
Merge pull request #855 from Tampere/fix/sap-wbs-id
Browse files Browse the repository at this point in the history
Fix/sap wbs
  • Loading branch information
mmoila authored Nov 23, 2023
2 parents 7b17b5b + d44201f commit ef2f3bb
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ node_modules
.temp
.vscode
.env.test-db
temp

9 changes: 7 additions & 2 deletions frontend/src/components/forms/SapProjectIdField.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import { TextFieldProps } from '@mui/material';
import { forwardRef } from 'react';

import { trpc } from '@frontend/client';
import { useTranslations } from '@frontend/stores/lang';

import { TextFieldWithStatus } from './TextFieldWithStatus';

export function SapProjectIdField(props: TextFieldProps & { value: string }) {
export const SapProjectIdField = forwardRef(function SapProjectIdField(
props: TextFieldProps & { value: string },
ref: React.ForwardedRef<HTMLDivElement | null>
) {
const { sap } = trpc.useContext();
const tr = useTranslations();

return (
<TextFieldWithStatus
ref={ref}
{...props}
validate={async (value) => {
return await sap.doesSapProjectIdExist.fetch({ projectId: value });
Expand All @@ -23,4 +28,4 @@ export function SapProjectIdField(props: TextFieldProps & { value: string }) {
}}
/>
);
}
});
10 changes: 7 additions & 3 deletions frontend/src/components/forms/TextFieldWithStatus.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Check, Error, Warning } from '@mui/icons-material';
import { CircularProgress, TextField, TextFieldProps, Tooltip } from '@mui/material';
import { useEffect, useMemo, useState } from 'react';
import { forwardRef, useEffect, useMemo, useState } from 'react';

import { useDebounce } from '@frontend/utils/useDebounce';

Expand All @@ -14,7 +14,10 @@ type Props = TextFieldProps & {
debounceDelayMs?: number;
};

export function TextFieldWithStatus(props: Props) {
export const TextFieldWithStatus = forwardRef(function TextFieldWithStatus(
props: Props,
ref: React.ForwardedRef<HTMLDivElement | null>
) {
const {
validate,
onStatusChange,
Expand Down Expand Up @@ -88,11 +91,12 @@ export function TextFieldWithStatus(props: Props) {

return (
<TextField
ref={ref}
{...TextFieldProps}
InputProps={{
...TextFieldProps.InputProps,
endAdornment: statusIcon,
}}
/>
);
}
});
1 change: 0 additions & 1 deletion frontend/src/views/ProjectObject/ProjectObject.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { TranslationKey } from '@shared/language';
import { DeleteProjectObjectDialog } from './DeleteProjectObjectDialog';
import { ProjectObjectFinances } from './ProjectObjectFinances';
import { ProjectObjectForm } from './ProjectObjectForm';
import { ProjectObjectOperativeForm } from './ProjectObjectOperativeForm';

type TabView = 'default' | 'talous' | 'tehtavat';

Expand Down
5 changes: 1 addition & 4 deletions frontend/src/views/ProjectObject/ProjectObjectForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,6 @@ export function ProjectObjectForm(props: Props) {

const formProjectId = form.watch('projectId');

useEffect(() => {
form.setValue('sapWBSId', null);
}, [formProjectId]);

const projectObjectUpsert = trpc.projectObject.upsert.useMutation({
onSuccess: (data) => {
if (!props.projectObject && data.id) {
Expand Down Expand Up @@ -318,6 +314,7 @@ export function ProjectObjectForm(props: Props) {
onChange={(value) => {
props.setProjectId?.(value ?? '');
field.onChange(value);
form.setValue('sapWBSId', null);
}}
/>
);
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/views/ProjectObject/SapWBSSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function SapWBSSelect(props: Props) {
autoHighlight
size="small"
ref={props.field.ref}
value={props.field.value}
value={props.field.value ?? null}
onChange={(_, value) => props.field.onChange(value)}
options={options ?? []}
noOptionsText={tr('sapWBSSelect.noOptions')}
Expand Down

0 comments on commit ef2f3bb

Please sign in to comment.