-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: init org details syncer (#118)
* refactor: init org details syncer * refactor: cleanup import path
- Loading branch information
Showing
5 changed files
with
78 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { atom } from 'jotai'; | ||
|
||
import { OrgListItem } from '~/orgs/core/schemas'; | ||
import { OrgDetails } from '~/orgs/core/schemas'; | ||
|
||
export const initOrgAtom = atom<OrgListItem | null>(null); | ||
export const initOrgAtom = atom<OrgDetails | null>(null); |
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,38 @@ | ||
import { useEffect } from 'react'; | ||
|
||
import { useAtom } from 'jotai'; | ||
|
||
import { useIsDesktop } from '~/shared/hooks/use-media-query'; | ||
|
||
import { activeOrgIdAtom } from '~/orgs/atoms/active-org-id-atom'; | ||
import { initOrgAtom } from '~/orgs/atoms/init-org-atom'; | ||
import { useOrgDetails } from '~/orgs/hooks/use-org-details'; | ||
|
||
interface Props { | ||
id: string; | ||
} | ||
|
||
export const InitOrgDetailsSyncer = ({ id }: Props) => { | ||
const [activeOrgId, setActiveOrgId] = useAtom(activeOrgIdAtom); | ||
const [initOrg, setInitOrg] = useAtom(initOrgAtom); | ||
|
||
const isDesktop = useIsDesktop(); | ||
|
||
const { data } = useOrgDetails(id); | ||
|
||
// Initialize org details | ||
useEffect(() => { | ||
if (!initOrg && data) { | ||
setInitOrg(data); | ||
} | ||
}, [data, initOrg, setInitOrg]); | ||
|
||
// Set active org ID on desktop | ||
useEffect(() => { | ||
if (isDesktop && !activeOrgId && data) { | ||
setActiveOrgId(data.orgId); | ||
} | ||
}, [activeOrgId, data, isDesktop, setActiveOrgId]); | ||
|
||
return null; | ||
}; |
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,17 @@ | ||
import { FundingRound } from '~/shared/core/schemas'; | ||
|
||
export const getFundingRoundsData = (fundingRounds: FundingRound[]) => { | ||
let lastFundingAmount = 0; | ||
let lastFundingDate = 0; | ||
|
||
if (fundingRounds.length > 0) { | ||
for (const fundingRound of fundingRounds) { | ||
if (fundingRound.date && fundingRound.date > (lastFundingDate ?? 0)) { | ||
lastFundingDate = fundingRound.date; | ||
lastFundingAmount = fundingRound.raisedAmount ?? 0; | ||
} | ||
} | ||
} | ||
|
||
return { lastFundingAmount, lastFundingDate }; | ||
}; |