-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add workflow creation from blueprint
- Loading branch information
1 parent
d07447e
commit 6ccea0b
Showing
11 changed files
with
108 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
apps/web/src/pages/get-started/components/CreateWorkflowButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import styled from '@emotion/styled'; | ||
|
||
import { colors } from '@novu/design-system'; | ||
|
||
import { ROUTES } from '../../../constants/routes.enum'; | ||
import { useCreateTemplateFromBlueprint } from '../../../api/hooks'; | ||
import { errorMessage } from '../../../utils/notifications'; | ||
import { getBlueprintTemplateById } from '../../../api/notification-templates'; | ||
import { getWorkflowBlueprintDetails } from '../../../utils'; | ||
import { TemplateCreationSourceEnum } from '../../templates/shared'; | ||
import { useSegment } from '../../../components/providers/SegmentProvider'; | ||
|
||
export function CreateWorkflowButton({ | ||
blueprintIdentifier, | ||
children, | ||
}: { | ||
blueprintIdentifier: string; | ||
children: string; | ||
}) { | ||
const openNewTab = (route: ROUTES, param: string) => | ||
window.open(`${window.location.origin}${route.replace(':templateId', param)}`, '_blank', 'noreferrer noopener'); | ||
|
||
const { createTemplateFromBlueprint } = useCreateTemplateFromBlueprint({ | ||
onSuccess: (template) => { | ||
openNewTab(ROUTES.WORKFLOWS_EDIT_TEMPLATEID, template._id ?? ''); | ||
}, | ||
onError: () => { | ||
errorMessage('Something went wrong while creating template from blueprint, please try again later.'); | ||
}, | ||
}); | ||
|
||
const { refetch } = useQuery( | ||
['blueprint', blueprintIdentifier], | ||
() => getBlueprintTemplateById(blueprintIdentifier as string), | ||
{ | ||
enabled: false, | ||
refetchOnWindowFocus: false, | ||
|
||
onSuccess: (data) => { | ||
if (data) { | ||
const { name: blueprintName } = getWorkflowBlueprintDetails(data.name); | ||
createTemplateFromBlueprint({ | ||
blueprint: { ...data, name: blueprintName }, | ||
params: { __source: TemplateCreationSourceEnum.ONBOARDING_GET_STARTED }, | ||
}); | ||
} | ||
}, | ||
} | ||
); | ||
|
||
const segment = useSegment(); | ||
const handleCreateTemplateClick = () => { | ||
segment.track('[Template Store] Click Create Notification Template', { | ||
templateIdentifier: blueprintIdentifier, | ||
location: TemplateCreationSourceEnum.ONBOARDING_GET_STARTED, | ||
}); | ||
|
||
refetch(); | ||
}; | ||
|
||
return <UnstyledButton onClick={() => handleCreateTemplateClick()}>{children}</UnstyledButton>; | ||
} | ||
|
||
export const UnstyledButton = styled.button` | ||
background: none; | ||
border: none; | ||
padding: 0; | ||
font: inherit; | ||
cursor: pointer; | ||
outline: inherit; | ||
color: ${colors.gradientEnd}; | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './utils'; | ||
export * from './pluralize'; | ||
export * from './templates'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { IconName } from '@fortawesome/fontawesome-svg-core'; | ||
|
||
export const getWorkflowBlueprintDetails = (templateName: string): { name: string; iconName: IconName } => { | ||
const regexResult = /^:.{1,}:/.exec(templateName); | ||
let name = ''; | ||
let iconName = 'fa-solid fa-question'; | ||
if (regexResult !== null) { | ||
name = templateName.replace(regexResult[0], '').trim(); | ||
iconName = regexResult[0].replace(/:/g, '').trim(); | ||
} | ||
|
||
return { name, iconName: iconName as IconName }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters