Skip to content

Commit

Permalink
draft(member-cards): WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
kirill-ivanovvv committed Jul 31, 2024
1 parent 0102dd6 commit 7a20dc7
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 49 deletions.
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
// import { getDiscordServerMembers } from '@globals/third-party-service-data'

import { INIT_ONBORDING_DATA } from '../member-cards-grid.constants.js'

export const checkMembersOnbordingConditions = async ({
membersData,
organizationsData,
membersInDefaultOrganization,
membersWithou2fa,
}) => {
// const discordServerMembers = await getDiscordServerMembers()
// console.log(discordServerMembers)

const resultMembersData = await membersData.map((memberData) => {
// console.log(memberData)
const { avatarUrl, id: memberId } = memberData
const { id: memberId } = memberData

const memberWithOnbordingData = memberData

memberWithOnbordingData.onbordingData = [...INIT_ONBORDING_DATA]
let memberWithOnbordingData = {
...memberData,
onbordingData: [...INIT_ONBORDING_DATA],
}

if (membersInDefaultOrganization.includes(memberId)) {
memberWithOnbordingData.onbordingData.forEach((conditionData, conditionIndex) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import type { GetViewerAllOrganizationsAllMembersQuery } from '@globals/data'
import type { OrganizationMemberType } from '@globals/data'

import { GET_VIEWER_ALL_ORGANIZATIONS_ALL_MEMBERS } from '@globals/data'
import { createOctokitRestClient } from '@globals/data'
import { OrganizationMemberDataType } from '@globals/data'
import { OrganizationDataType } from '@globals/data'
import { octokitGraphqlClient } from '@globals/data'
import { getGithubOrganizationMembersWithout2fa } from '@globals/data'
import { getTokenCookie } from '@globals/helpers'

import { checkMembersOnbordingConditions } from './check-members-onbording-conditions.hook.js'
import { getMembersWithout2fa } from './get-members-withot-2fa.hook.js'
import { getUniqueItems } from './helpers/index.js'
import { linkMemberToOrganizations } from './helpers/index.js'

Expand All @@ -31,56 +32,47 @@ export const getMembersData: GetMembersDataType = async ({
})) as GetViewerAllOrganizationsAllMembersQuery

const organizationsData_response = response.viewer.organizations.nodes
if (!organizationsData_response?.length) return

const defaultOrganizationName = process.env.NEXT_PUBLIC_GITHUB_ORG_NAME as string
const membersInDefaultOrganization = []

const restClient = createOctokitRestClient(token)
const query = getGithubOrganizationMembersWithout2fa({
organizatoinName: defaultOrganizationName,
}) as [any]

const restResponse = await restClient(...query)

const membersWithou2fa = []

if (restResponse.data.length) {
for (const { id: memberId } of restResponse.data) {
membersWithou2fa.push(memberId)
}
}

// TODO interfaces
const membersData_all: any[] = []
const organizationsData_all: any[] = []
const membersData_all: Array<OrganizationMemberDataType> = []
const organizationsData_all: Array<OrganizationDataType> = []
const memberOrganizations: Record<string, Array<string>> = {}

if (!organizationsData_response?.length) return
const defaultOrganizationName = process.env.NEXT_PUBLIC_GITHUB_ORG_NAME as string
const membersWithou2fa = await getMembersWithout2fa(token)
const membersInDefaultOrganization: Array<string> = []

for (const organizationData of organizationsData_response) {
if (organizationData.name === defaultOrganizationName) {
const {
membersWithRole: { nodes: organizationMembers },
} = organizationData

for (const { id: memberId } of organizationMembers) {
if (!organizationData) continue
const {
membersWithRole: { nodes: organizationMembers },
} = organizationData
if (!organizationMembers) continue

for (const { id: memberId } of organizationMembers as any) {
if (organizationData.name === defaultOrganizationName) {
membersInDefaultOrganization.push(memberId)
}
}

const membersData_organization = organizationData?.membersWithRole
.nodes as Array<OrganizationMemberType>
const {
membersWithRole: { nodes: membersData_organization },
} = organizationData

for (const memberData of membersData_organization) {
const { id: memberId } = memberData
// TODO interface
const { id: organizationId } = organizationData as any
if (!membersData_organization) continue

for (const { id: memberId } of membersData_organization) {
const { id: organizationId } = organizationData

if (!memberOrganizations[memberId]) {
memberOrganizations[memberId] = []
}

memberOrganizations[memberId].push(organizationId)

if (organizationData.name === defaultOrganizationName) {
membersInDefaultOrganization.push(memberId)
}
}

membersData_all.push(...membersData_organization)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { createOctokitRestClient } from '@globals/data'
import { getGithubOrganizationMembersWithout2fa } from '@globals/data'

export const getMembersWithout2fa = async (token) => {
const defaultOrganizationName = process.env.NEXT_PUBLIC_GITHUB_ORG_NAME as string

const membersWithou2fa = []

const restClient = createOctokitRestClient(token)
const query = getGithubOrganizationMembersWithout2fa({
organizatoinName: defaultOrganizationName,
}) as [any]

const restResponse = await restClient(...query)

if (restResponse.data.length) {
for (const { id: memberId } of restResponse.data) {
membersWithou2fa.push(memberId)
}
}

return membersWithou2fa
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const checkMemberInDefaultOrganization = () => {}
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ const MemberCardsGrid: FC<MemberCardsGridProps> = memo(({
const theme = useTheme() as ThemeType
const toast = useToast()

// const [pendingMembersData, setPendingMembersData] = useState<Array<OrganizationMemberType>>([])
const pendingMembersData = []

// TODO member with onbording data interface
const [membersData, setMembersData] = useState<Array<MemberWithOnbordingDataType>>([])
const [organizationsData, setOrganizationsData] = useState<Array<OrganizationDataType>>([])

Expand Down

0 comments on commit 7a20dc7

Please sign in to comment.