diff --git a/src/Sass/_domains.scss b/src/Sass/_domains.scss index f917dac..08c3111 100644 --- a/src/Sass/_domains.scss +++ b/src/Sass/_domains.scss @@ -11,26 +11,3 @@ grid-template-columns: fit-content(50%) auto; grid-gap: $gridGap; } - -.mail-types { - padding-left: 0rem; - list-style: none; - width: $mailtemplateNameListWidth; - - li { - cursor: pointer; - padding: 0.5rem 0.75rem; - border-radius: 4px; - transition: background-color 0.2s ease; - - &:hover { - background-color: rgba(0, 0, 0, 0.05); - } - - &.selected { - background-color: #0078d4; - color: white; - font-weight: 500; - } - } -} diff --git a/src/Sass/global.scss b/src/Sass/global.scss index c681843..df7d32a 100644 --- a/src/Sass/global.scss +++ b/src/Sass/global.scss @@ -29,6 +29,7 @@ @import "./_expandableCell.scss"; @import "./_errorLogs.scss"; @import "./addTaskButton.scss"; +@import "./selectableList.scss"; //Changes needed to make MS Edge behave the same as other browsers input::-ms-reveal { diff --git a/src/Sass/selectableList.scss b/src/Sass/selectableList.scss new file mode 100644 index 0000000..ae45018 --- /dev/null +++ b/src/Sass/selectableList.scss @@ -0,0 +1,22 @@ +.selectable-list { + padding-left: 0rem; + list-style: none; + width: $mailtemplateNameListWidth; + + li { + cursor: pointer; + padding: 0.5rem 0.75rem; + border-radius: 4px; + transition: background-color 0.2s ease; + + &:hover { + background-color: rgba(0, 0, 0, 0.05); + } + + &.selected { + background-color: #0078d4; + color: white; + font-weight: 500; + } + } +} diff --git a/src/components/common/SelectableList.tsx b/src/components/common/SelectableList.tsx new file mode 100644 index 0000000..348320d --- /dev/null +++ b/src/components/common/SelectableList.tsx @@ -0,0 +1,33 @@ +import React from "react"; + +export interface SelectableListProps { + items: T[]; + selectedValue?: t | null; + renderLabel: (item: T) => React.ReactNode; + onSelect: (item: T) => void; +} + +export const SelectableList = ( + props: SelectableListProps, +): JSX.Element => { + const { items, selectedValue, renderLabel, onSelect } = props; + + const listClassName = "selectable-list"; + + return ( +
    + {items.map((item, index) => { + const isSelected = selectedValue === item; + const className = isSelected + ? ["selected"].filter(Boolean).join(" ") + : ""; + + return ( +
  • onSelect(item)} className={className}> + {renderLabel(item)} +
  • + ); + })} +
+ ); +}; diff --git a/src/components/common/useForm.ts b/src/components/common/useForm.ts index 6311ac7..47f8892 100644 --- a/src/components/common/useForm.ts +++ b/src/components/common/useForm.ts @@ -102,6 +102,7 @@ export const useForm = (initialState: FormState): UseFormReturn => { const initialDataRef = useRef( JSON.parse(JSON.stringify(initialState.data)), ); + const wasLoadedRef = useRef(initialState.loaded); const setState = useCallback((updates: Partial) => { setStateInternal((prev) => ({ ...prev, ...updates })); @@ -621,6 +622,14 @@ export const useForm = (initialState: FormState): UseFormReturn => { return cleanup; }, [setupNavigationGuard]); + useEffect(() => { + if (!wasLoadedRef.current && state.loaded) { + initialDataRef.current = JSON.parse(JSON.stringify(state.data)); + } + + wasLoadedRef.current = state.loaded; + }, [state.loaded, state.data]); + const api: any = { state, schema: schemaRef.current, diff --git a/src/modules/manager/domains/components/MailTemplatesTab.tsx b/src/modules/manager/domains/components/MailTemplatesTab.tsx index c9836af..b4c4036 100644 --- a/src/modules/manager/domains/components/MailTemplatesTab.tsx +++ b/src/modules/manager/domains/components/MailTemplatesTab.tsx @@ -1,10 +1,11 @@ -import React, { useEffect, useState, useCallback, Suspense } from "react"; +import React, { useEffect, useState } from "react"; import { useParams } from "react-router-dom"; import mailTemplatesService from "../serrvices/mailTemplatesService"; import HOCEmailTemplateEditor from "./EmailTemplateEditor"; import Loading from "../../../../components/common/Loading"; import { Namespaces } from "../../../../i18n/i18n"; import { useTranslation } from "react-i18next"; +import { SelectableList } from "../../../../components/common/SelectableList"; interface MailType { mailType: string; @@ -13,35 +14,27 @@ interface MailType { const MailTemplatesTabContent: React.FC<{ types: MailType[]; - currentMailType: string; + currentMailType: MailType | null; domainId: string | undefined; - onClick: (e: React.MouseEvent) => void; + onClick: (item: MailType) => void; }> = ({ types, currentMailType, domainId, onClick }) => { const { t: tMail } = useTranslation(Namespaces.MailTypes); return (
-
    - {types.map((x) => { - return ( -
  • - {tMail(x.mailType)} -
  • - ); - })} -
+ tMail(x.mailType)} + onSelect={(item) => onClick(item)} + />
{domainId && currentMailType ? ( ) : null}
@@ -51,7 +44,7 @@ const MailTemplatesTabContent: React.FC<{ const MailTemplatesTab: React.FC = () => { const [loaded, setLoaded] = useState(false); - const [currentMailType, setCurrentMailType] = useState(""); + const [currentMailType, setCurrentMailType] = useState(null); const [types, setTypes] = useState([]); useEffect(() => { @@ -62,7 +55,7 @@ const MailTemplatesTab: React.FC = () => { setTypes(nextTypes); if (nextTypes.length > 0) { - setCurrentMailType(nextTypes[0].mailType); + setCurrentMailType(nextTypes[0]); } } catch (ex) { console.error(ex); @@ -74,34 +67,20 @@ const MailTemplatesTab: React.FC = () => { void loadTypes(); }, []); - const selectTemplate = useCallback( - (emailType: string) => { - if (currentMailType !== emailType) { - setCurrentMailType(emailType); - } - }, - [currentMailType], - ); - - const onClick = (e: React.MouseEvent) => { - const value = (e.target as HTMLElement).getAttribute("value"); - if (value) { - selectTemplate(value); - } + const onClick = (item: MailType) => { + setCurrentMailType(item); }; const { domainId } = useParams<{ domainId: string }>(); return ( - Loading...
}> - - + ); }; diff --git a/src/modules/manager/workflowTemplates/components/TaskList.tsx b/src/modules/manager/workflowTemplates/components/TaskList.tsx index 1a33fc7..30d65b8 100644 --- a/src/modules/manager/workflowTemplates/components/TaskList.tsx +++ b/src/modules/manager/workflowTemplates/components/TaskList.tsx @@ -1,4 +1,4 @@ -import React from "react"; +import React, { useState } from "react"; import { TaskDefinition, TaskMetadata, @@ -6,6 +6,7 @@ import { import AddTaskButton from "./AddTaskButton"; import { Namespaces } from "../../../../i18n/i18n"; import { useTranslation } from "react-i18next"; +import { SelectableList } from "../../../../components/common/SelectableList"; interface TaskListProps { tasks: TaskDefinition[]; @@ -16,14 +17,30 @@ interface TaskListProps { const TaskList: React.FC = ({ tasks, taskType, onChange }) => { const { t: tTaskType } = useTranslation(Namespaces.TaskTypes); + const [currentTask, setCurrentTask] = useState(null); + + const formatNewTaskName = ( + displayName: string, + tasks: TaskDefinition>[], + ) => { + return `${tTaskType(displayName)} ${tasks.length + 1}`; + }; + const handleAddTask = (selectedType: TaskMetadata) => { + const formattedName = formatNewTaskName(selectedType.displayName, tasks); + const newTask: TaskDefinition = { type: selectedType.taskType, - config: { name: tTaskType(selectedType.displayName) }, + config: { + name: formattedName, + guid: crypto.randomUUID(), + }, }; - console.log("Add Task clicked"); + if (tasks.length === 0) { + setCurrentTask(newTask); + } onChange([...tasks, newTask]); }; @@ -31,11 +48,12 @@ const TaskList: React.FC = ({ tasks, taskType, onChange }) => {
-
    - {tasks.map((task, index) => ( -
  • {task.type}
  • - ))} -
+ x.config.name as string} + onSelect={(item) => setCurrentTask(item)} + />
); }; diff --git a/src/modules/manager/workflowTemplates/services/WorkflowTemplateService.ts b/src/modules/manager/workflowTemplates/services/WorkflowTemplateService.ts index 44c55f0..95f5d9c 100644 --- a/src/modules/manager/workflowTemplates/services/WorkflowTemplateService.ts +++ b/src/modules/manager/workflowTemplates/services/WorkflowTemplateService.ts @@ -30,7 +30,7 @@ export type ReadWorkflowTemplateVersion = { export interface TaskDefinition> { type: string; - config?: TConfig; + config: TConfig; } export interface CreateWorkflowTemplateVersion extends FormData {