diff --git a/src/containers/Flow/Flow.test.tsx b/src/containers/Flow/Flow.test.tsx index fb8503702..221f7bf59 100644 --- a/src/containers/Flow/Flow.test.tsx +++ b/src/containers/Flow/Flow.test.tsx @@ -83,6 +83,17 @@ const mocks = [ addRoleIds: [], deleteRoleIds: [], }), + copyFlowQuery({ + isActive: true, + isPinned: false, + isBackground: false, + name: 'Help flow', + keywords: ['help'], + description: '', + ignoreKeywords: false, + addRoleIds: [], + deleteRoleIds: [], + }), ]; const mockUseLocationValue: any = { @@ -361,12 +372,16 @@ it('should create copy of a template flow', async () => { const { container, getByTestId } = render(copyFlow()); await waitFor(() => { - const inputElement = container.querySelector('input[name="name"]') as HTMLInputElement; - expect(inputElement?.value).toBe('Copy of Help'); + expect(screen.getByText('Copy of Help')).toBeInTheDocument(); }); const button = getByTestId('submitActionButton'); fireEvent.click(button); + + const inputs = screen.getAllByRole('textbox'); + fireEvent.change(inputs[0], { target: { value: 'Help flow' } }); + fireEvent.change(inputs[1], { target: { value: 'help' } }); + await waitFor(() => {}); }); diff --git a/src/containers/Flow/Flow.tsx b/src/containers/Flow/Flow.tsx index 150767345..b11205a3b 100644 --- a/src/containers/Flow/Flow.tsx +++ b/src/containers/Flow/Flow.tsx @@ -43,6 +43,8 @@ export const Flow = () => { const [roles, setRoles] = useState>([]); const [isBackground, setIsBackground] = useState(false); const [ignoreKeywords, setIgnoreKeywords] = useState(false); + const [copyFlowTitle, setCopyFlowTitle] = useState(''); + const { t } = useTranslation(); let isTemplate = false; @@ -104,11 +106,14 @@ export const Flow = () => { if (location.state === 'copy') { fieldName = `Copy of ${nameValue}`; fieldKeywords = ''; + description = `Copy of ${nameValue}`; + setCopyFlowTitle(nameValue); } else if (location.state === 'copyTemplate') { - fieldName = `Copy of ${nameValue}`; - description = ''; + fieldName = ''; + description = `Copy of ${nameValue}`; tags = null; fieldKeywords = ''; + setCopyFlowTitle(nameValue); } const { organization: { @@ -140,8 +145,7 @@ export const Flow = () => { } }; - const regex = - /^\s*[^-!$%^&*()+|~=`{}[\]:";'<>?,./]+\s*(,\s*[^-!$%^&*()+|~=`{}[\]:";'<>?,./]+\s*)*$/g; + const regex = /^\s*[^-!$%^&*()+|~=`{}[\]:";'<>?,./\s]+\s*(,\s*[^-!$%^&*()+|~=`{}[\]:";'<>?,./\s]+\s*)*$/g; const FormSchema = Yup.object().shape({ name: Yup.string().required(t('Name is required.')), @@ -215,9 +219,7 @@ export const Flow = () => { name: 'ignoreKeywords', title: t('Ignore Keywords'), info: { - title: t( - 'If activated, users will not be able to change this flow by entering keyword for any other flow.' - ), + title: t('If activated, users will not be able to change this flow by entering keyword for any other flow.'), }, darkCheckbox: true, className: styles.Checkbox, @@ -280,12 +282,12 @@ export const Flow = () => { if (location.state === 'copy') { queries.updateItemQuery = CREATE_FLOW_COPY; - title = t('Copy flow'); + title = t('Copy of'); type = 'copy'; copyNotification = t('Copy of the flow has been created!'); } else if (location.state === 'copyTemplate') { queries.updateItemQuery = CREATE_FLOW_COPY; - title = t('Template flow copy'); + title = t('Copy of'); type = 'copy'; copyNotification = t('Flow created successfully from template!'); } else if (location.state === 'template') { @@ -294,6 +296,10 @@ export const Flow = () => { queries.updateItemQuery = UPDATE_FLOW; } + if (copyFlowTitle) { + title = `${title} ${copyFlowTitle}`; + } + const customHandler = (data: any) => { let dataCopy = data; if (data[0].key === 'keywords') { diff --git a/src/i18n/en/en.json b/src/i18n/en/en.json index ae0067c2b..fe56b8a3a 100644 --- a/src/i18n/en/en.json +++ b/src/i18n/en/en.json @@ -182,7 +182,7 @@ "If activated, users will not be able to change this flow by entering keyword for any other flow.": "If activated, users will not be able to change this flow by entering keyword for any other flow.", "Is pinned?": "Is pinned?", "Run this flow in the background": "Run this flow in the background", - "Copy flow": "Copy flow", + "Copy of": "Copy of", "Sorry! An error occurred!": "Sorry! An error occurred!", "Copy of the flow has been created!": "Copy of the flow has been created!", "Import flow": "Import flow", @@ -511,7 +511,6 @@ "Import the csv with translations for interactive message.": "Import the csv with translations for interactive message.", "Template Flows": "Template Flows", "Template Flow": "Template Flow", - "Template flow copy": "Template flow copy", "Flow created successfully from template!": "Flow created successfully from template!", "Select/Create an assistant": "Select/Create an assistant", "Create Assistant": "Create Assistant",