-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(web): add changes sync changes dot indication (#6042)
Co-authored-by: Dima Grossman <[email protected]>
- Loading branch information
1 parent
a5f5657
commit aac8132
Showing
11 changed files
with
179 additions
and
28 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
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { useMemo } from 'react'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
|
||
import { INotificationTemplate } from '@novu/shared'; | ||
|
||
import { getNotificationsList } from '../api/notification-templates'; | ||
import { useDiscover } from '../studio/hooks'; | ||
import { createHash } from '../utils/create-hash'; | ||
|
||
export function useIsSynced() { | ||
const { data: bridgeDiscoverData, isLoading: isLoadingBridgeWorkflows } = useDiscover(); | ||
const { | ||
data: originData, | ||
isLoading: isLoadingOriginWorkflows, | ||
refetch, | ||
} = useQuery( | ||
['origin-workflows'], | ||
async () => { | ||
return getNotificationsList({ page: 0, limit: 100 }); | ||
}, | ||
{} | ||
); | ||
|
||
const isSynced = useMemo(() => { | ||
if (isLoadingBridgeWorkflows || isLoadingOriginWorkflows) { | ||
return true; | ||
} | ||
|
||
const bridgeDiscoverWorkflows = bridgeDiscoverData?.workflows || undefined; | ||
const originWorkflows = originData?.data.map((workflow: INotificationTemplate) => workflow.rawData) || undefined; | ||
|
||
const bridgeDiscoverWorkflowsHash = createHash(JSON.stringify(bridgeDiscoverWorkflows || '')); | ||
const storedWorkflowsHash = createHash(JSON.stringify(originWorkflows || '')); | ||
|
||
return storedWorkflowsHash === bridgeDiscoverWorkflowsHash; | ||
}, [bridgeDiscoverData, originData, isLoadingBridgeWorkflows, isLoadingOriginWorkflows]); | ||
|
||
return { isSynced, refetchOriginWorkflows: refetch }; | ||
} |
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,5 @@ | ||
import CryptoJS from 'crypto-js'; | ||
|
||
export const createHash = (message: string) => { | ||
return CryptoJS.SHA256(message).toString(CryptoJS.enc.Hex); | ||
}; |
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
Oops, something went wrong.