diff --git a/src/core_modules/capture-core/components/WidgetEventSchedule/hooks/useCommentDetails.js b/src/core_modules/capture-core/components/WidgetEventSchedule/hooks/useCommentDetails.js index 21394c5a8d..4544faf9af 100644 --- a/src/core_modules/capture-core/components/WidgetEventSchedule/hooks/useCommentDetails.js +++ b/src/core_modules/capture-core/components/WidgetEventSchedule/hooks/useCommentDetails.js @@ -1,7 +1,7 @@ // @flow import { useMemo } from 'react'; import { useDataQuery } from '@dhis2/app-runtime'; -import uuid from 'd2-utilizr/lib/uuid'; +import { generateUID } from '../../../utils/uid/generateUID'; export const useCommentDetails = () => { const { data, error, loading } = useDataQuery(useMemo(() => ({ @@ -18,6 +18,6 @@ export const useCommentDetails = () => { return { error, currentUser: !loading && data.currentUser, - noteId: uuid(), + noteId: generateUID(), }; }; diff --git a/src/core_modules/capture-core/utils/uid/generateUID.js b/src/core_modules/capture-core/utils/uid/generateUID.js new file mode 100644 index 0000000000..addcb13f49 --- /dev/null +++ b/src/core_modules/capture-core/utils/uid/generateUID.js @@ -0,0 +1,18 @@ +// @flow + +export const generateUID = (): string => { + const letters = 'abcdefghijklmnopqrstuvwxyz' + 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; + const allowedChars = `0123456789${letters}`; + const NUMBER_OF_CODEPOINTS = allowedChars.length; + const CODESIZE = 11; + let uid; + + // the uid should start with a char + uid = letters.charAt(Math.random() * (letters.length)); + + for (let i = 1; i < CODESIZE; ++i) { + uid += allowedChars.charAt(Math.random() * (NUMBER_OF_CODEPOINTS)); + } + + return uid; +};