-
-
Notifications
You must be signed in to change notification settings - Fork 478
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core,console): social connector targets (#851)
* feat(core,console): social connector targets * fix: add test
- Loading branch information
Showing
19 changed files
with
186 additions
and
108 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { ConnectorDTO } from '@logto/schemas'; | ||
import { useMemo } from 'react'; | ||
import useSWR from 'swr'; | ||
|
||
import { RequestError } from '@/hooks/use-api'; | ||
import { ConnectorGroup } from '@/types/connector'; | ||
|
||
// Group connectors by target | ||
const useConnectorGroups = () => { | ||
const { data, ...rest } = useSWR<ConnectorDTO[], RequestError>('/api/connectors'); | ||
|
||
const groups = useMemo(() => { | ||
if (!data) { | ||
return; | ||
} | ||
|
||
return data.reduce<ConnectorGroup[]>((previous, item) => { | ||
const groupIndex = previous.findIndex(({ target }) => target === item.target); | ||
|
||
if (groupIndex === -1) { | ||
return [ | ||
...previous, | ||
{ | ||
name: item.metadata.name, | ||
logo: item.metadata.logo, | ||
target: item.metadata.target, | ||
enabled: item.enabled, | ||
connectors: [item], | ||
}, | ||
]; | ||
} | ||
|
||
return previous.map((group, index) => { | ||
if (index !== groupIndex) { | ||
return group; | ||
} | ||
|
||
return { | ||
...group, | ||
connectors: [...group.connectors, item], | ||
// Group is enabled when any of its connectors is enabled. | ||
enabled: group.enabled || item.enabled, | ||
}; | ||
}); | ||
}, []); | ||
}, [data]); | ||
|
||
return { | ||
...rest, | ||
data: groups, | ||
}; | ||
}; | ||
|
||
export default useConnectorGroups; |
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,6 @@ | ||
import { ConnectorDTO } from '@logto/schemas'; | ||
|
||
export type ConnectorGroup = Pick<ConnectorDTO['metadata'], 'name' | 'logo' | 'target'> & { | ||
enabled: boolean; | ||
connectors: ConnectorDTO[]; | ||
}; |
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
Oops, something went wrong.