Skip to content

Commit 35dbb10

Browse files
authored
change the way we get case base name (#579)
* change the way we get case base name
1 parent 75b9a45 commit 35dbb10

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/components/dialogs/commons/prefilled-name-input.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { useEffect, useState } from 'react';
99
import { useFormContext } from 'react-hook-form';
1010
import { ElementType, FieldConstants, UniqueNameInput } from '@gridsuite/commons-ui';
1111
import { useSelector } from 'react-redux';
12-
import { elementExists } from '../../../utils/rest-api';
12+
import { elementExists, getBaseName } from '../../../utils/rest-api';
1313
import { AppState } from '../../../redux/types';
1414

1515
export interface PrefilledNameInputProps {
@@ -45,9 +45,15 @@ export default function PrefilledNameInput({ label, name, elementType }: Readonl
4545

4646
if (caseName) {
4747
clearErrors(name);
48-
setValue(name, caseName?.substring(0, caseName.indexOf('.')), {
49-
shouldDirty: true,
50-
});
48+
getBaseName(caseName)
49+
.then((response) => {
50+
setValue(name, response, {
51+
shouldDirty: true,
52+
});
53+
})
54+
.catch((error) => {
55+
console.error('Error fetching base name:', error);
56+
});
5157
}
5258
}
5359
}, [caseFile, modifiedByUser, apiCallErrorMessage, caseFileErrorMessage, setValue, clearErrors, name]);

src/utils/rest-api.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,3 +816,11 @@ export function searchElementsInfos(searchTerm: string, currentDirectoryUuid: UU
816816
}
817817
);
818818
}
819+
820+
export const getBaseName = (caseName: string) => {
821+
const caseNameUrl = `${PREFIX_CASE_QUERIES}/v1/cases/caseBaseName?caseName=${encodeURIComponent(caseName)}`;
822+
console.info('Get base name for case', caseName);
823+
return backendFetchText(caseNameUrl, {
824+
method: 'GET',
825+
});
826+
};

0 commit comments

Comments
 (0)