-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(BudgetInput): support value accessors in BudgetInputs
- Loading branch information
Showing
21 changed files
with
1,275 additions
and
158 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { createContext, useContext } from 'react'; | ||
import { MonthData } from '../budget'; | ||
|
||
const MonthsContext = createContext<MonthData[]>([]); | ||
const MonthContext = createContext<MonthData | null>(null); | ||
|
||
export const MonthsContextProvider = MonthsContext.Provider; | ||
export const MonthContextProvider = MonthContext.Provider; | ||
|
||
export function useMonths() { | ||
return useContext(MonthsContext); | ||
} | ||
export function useMonth() { | ||
const month = useContext(MonthContext); | ||
if (month === null) { | ||
throw new Error('Can not useMonth outside of MonthContextProvider'); | ||
} | ||
return month; | ||
} |
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,28 @@ | ||
import { BudgetCategoryRow } from '../../../budget'; | ||
import faker from 'faker'; | ||
|
||
let i = 0; | ||
|
||
export function createCategoryRow({ | ||
budgeted = 0, | ||
spend = 0, | ||
balance = 0, | ||
name = `${faker.commerce.department()}${i++}`, | ||
uuid = `${faker.random.uuid()}${i}`, | ||
indentation = 0, | ||
overspendRollover = false, | ||
group = false, | ||
transactions = [], | ||
}: Partial<BudgetCategoryRow>): BudgetCategoryRow { | ||
return { | ||
budgeted, | ||
spend, | ||
balance, | ||
name, | ||
uuid, | ||
indentation, | ||
overspendRollover, | ||
group, | ||
transactions, | ||
}; | ||
} |
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,3 @@ | ||
export * from './categoryRow'; | ||
export * from './monthData'; | ||
export * from './numberFormatter'; |
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,37 @@ | ||
import format from 'date-fns/format'; | ||
import { MonthData, DetailedMonthData } from '../../../budget'; | ||
import formatDateKey from '../../formatDateKey'; | ||
|
||
export function createMonthData( | ||
date: Date, | ||
{ | ||
uncategorized = { amount: 0, transactions: [] }, | ||
categories = [], | ||
toBudget = 0, | ||
total = { spend: 0, balance: 0, budgeted: 0 }, | ||
overspendPrevMonth = 0, | ||
overspendRolloverState = {}, | ||
available = [], | ||
income = { amount: 0, transactions: [] }, | ||
availableThisMonth = { amount: 0, transactions: [] }, | ||
rollover = { total: 0 }, | ||
}: Partial<DetailedMonthData> = {}, | ||
): MonthData { | ||
return { | ||
key: formatDateKey(date), | ||
date, | ||
name: format(date, 'MMMM'), | ||
get: () => ({ | ||
uncategorized, | ||
categories, | ||
toBudget, | ||
total, | ||
income, | ||
overspendPrevMonth, | ||
overspendRolloverState, | ||
available, | ||
availableThisMonth, | ||
rollover, | ||
}), | ||
}; | ||
} |
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,20 @@ | ||
import { NumberFormatter } from '../../createNumberFormatter'; | ||
|
||
const ni = () => { | ||
throw new Error('Not Implemented'); | ||
}; | ||
export function createNumberFormatter({ | ||
fractionStep = 0.1, | ||
fractionDelimiter = '.', | ||
delimiters = [',', '.'], | ||
format = ni, | ||
parse = ni, | ||
}: Partial<NumberFormatter> = {}): NumberFormatter { | ||
return { | ||
fractionDelimiter, | ||
fractionStep, | ||
delimiters, | ||
format, | ||
parse, | ||
}; | ||
} |
Oops, something went wrong.