-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mobile): [Budget] add budget list
- Loading branch information
Showing
17 changed files
with
656 additions
and
73 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { cn } from '@/lib/utils' | ||
import type { BudgetPopulated } from '@6pm/validation' | ||
import { t } from '@lingui/macro' | ||
import { useLingui } from '@lingui/react' | ||
import { formatDuration, intervalToDuration } from 'date-fns' | ||
import { Link } from 'expo-router' | ||
import { type FC, useMemo } from 'react' | ||
import { Pressable, View } from 'react-native' | ||
|
||
import { calculateBudgetPeriodStartEndDates } from '@6pm/utilities' | ||
import { Progress } from '../ui/progress' | ||
import { Text } from '../ui/text' | ||
|
||
type BudgetItemProps = { | ||
budget: BudgetPopulated | ||
} | ||
|
||
export const BudgetItem: FC<BudgetItemProps> = ({ budget }) => { | ||
const { i18n } = useLingui() | ||
|
||
const remainingBalance = 0 | ||
|
||
const remainingDays = useMemo(() => { | ||
let periodEndDate: Date | null | ||
if (budget.periodConfig.type === 'CUSTOM') { | ||
periodEndDate = budget.periodConfig.endDate | ||
} else { | ||
const { endDate } = calculateBudgetPeriodStartEndDates({ | ||
anchorDate: new Date(), | ||
type: budget.periodConfig.type, | ||
}) | ||
periodEndDate = endDate | ||
} | ||
|
||
if (!periodEndDate) { | ||
return t(i18n)`Unknown` | ||
} | ||
|
||
const duration = formatDuration( | ||
intervalToDuration({ | ||
start: new Date(), | ||
end: periodEndDate, | ||
}), | ||
{ | ||
format: ['days', 'hours'], | ||
delimiter: ',', | ||
}, | ||
) | ||
|
||
return t(i18n)`${duration?.split(',')[0]} left` | ||
}, [budget.periodConfig, i18n]) | ||
|
||
return ( | ||
<Link | ||
asChild | ||
push | ||
href={{ | ||
pathname: '/budget/[budgetId]', | ||
params: { budgetId: budget.id }, | ||
}} | ||
> | ||
<Pressable className="gap-3 mb-3 mt-1 justify-between px-4 py-3 active:bg-muted border border-border rounded-lg"> | ||
<View className="flex-row items-center gap-6 justify-between"> | ||
<Text numberOfLines={1} className="flex-1 line-clamp-1 font-semibold"> | ||
{budget.name} | ||
</Text> | ||
<Text | ||
className={cn( | ||
'font-semibold shrink-0 text-xl', | ||
remainingBalance < 0 && 'text-amount-negative', | ||
)} | ||
> | ||
{Math.abs(remainingBalance).toLocaleString() ?? '0.00'}{' '} | ||
<Text className="text-muted-foreground text-[10px] font-normal"> | ||
{budget.preferredCurrency} | ||
</Text> | ||
</Text> | ||
</View> | ||
<Progress value={50} className="h-1.5" /> | ||
<View className="flex-row items-center gap-6 justify-between"> | ||
<Text | ||
numberOfLines={1} | ||
className="flex-1 line-clamp-1 text-muted-foreground text-sm" | ||
> | ||
{remainingDays} | ||
</Text> | ||
<Text className="text-sm font-normal">50%</Text> | ||
</View> | ||
</Pressable> | ||
</Link> | ||
) | ||
} |
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 { t } from '@lingui/macro' | ||
import { useLingui } from '@lingui/react' | ||
import { View } from 'react-native' | ||
import { Text } from '../ui/text' | ||
|
||
type BudgetStatisticProps = { | ||
totalRemaining: number | ||
remainingPerDay: number | ||
} | ||
|
||
export function BudgetStatistic({ | ||
totalRemaining, | ||
remainingPerDay, | ||
}: BudgetStatisticProps) { | ||
const { i18n } = useLingui() | ||
|
||
return ( | ||
<View className="flex-row items-center gap-6 justify-between"> | ||
<View className="gap-1"> | ||
<Text className="font-semibold text-2xl"> | ||
{totalRemaining?.toLocaleString() || '0.00'}{' '} | ||
<Text className="text-muted-foreground font-normal text-sm">VND</Text> | ||
</Text> | ||
<Text className="text-muted-foreground text-sm"> | ||
{t(i18n)`Left this month`} | ||
</Text> | ||
</View> | ||
<View className="gap-1"> | ||
<Text className="font-semibold text-2xl text-right"> | ||
{remainingPerDay?.toLocaleString() || '0.00'}{' '} | ||
<Text className="text-muted-foreground font-normal text-sm">VND</Text> | ||
</Text> | ||
<Text className="text-muted-foreground text-sm text-right"> | ||
{t(i18n)`Left per day`} | ||
</Text> | ||
</View> | ||
</View> | ||
) | ||
} |
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 { View } from 'react-native' | ||
|
||
export function BurndownChart() { | ||
return <View className="bg-gray-100 rounded-lg h-[187px] w-full" /> | ||
} |
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,75 @@ | ||
import { cn } from '@/lib/utils' | ||
import * as ProgressPrimitive from '@rn-primitives/progress' | ||
import * as React from 'react' | ||
import { Platform, View } from 'react-native' | ||
import Animated, { | ||
Extrapolation, | ||
interpolate, | ||
useAnimatedStyle, | ||
useDerivedValue, | ||
withSpring, | ||
} from 'react-native-reanimated' | ||
|
||
const Progress = React.forwardRef< | ||
React.ElementRef<typeof ProgressPrimitive.Root>, | ||
React.ComponentPropsWithoutRef<typeof ProgressPrimitive.Root> & { | ||
indicatorClassName?: string | ||
} | ||
>(({ className, value, indicatorClassName, ...props }, ref) => { | ||
return ( | ||
<ProgressPrimitive.Root | ||
ref={ref} | ||
className={cn( | ||
'relative h-4 w-full overflow-hidden rounded-full bg-secondary', | ||
className, | ||
)} | ||
{...props} | ||
> | ||
<Indicator value={value} className={indicatorClassName} /> | ||
</ProgressPrimitive.Root> | ||
) | ||
}) | ||
Progress.displayName = ProgressPrimitive.Root.displayName | ||
|
||
export { Progress } | ||
|
||
function Indicator({ | ||
value, | ||
className, | ||
}: { value: number | undefined | null; className?: string }) { | ||
const progress = useDerivedValue(() => value ?? 0) | ||
|
||
const indicator = useAnimatedStyle(() => { | ||
return { | ||
width: withSpring( | ||
`${interpolate(progress.value, [0, 100], [1, 100], Extrapolation.CLAMP)}%`, | ||
{ overshootClamping: true }, | ||
), | ||
} | ||
}) | ||
|
||
if (Platform.OS === 'web') { | ||
return ( | ||
<View | ||
className={cn( | ||
'h-full w-full flex-1 bg-primary web:transition-all', | ||
className, | ||
)} | ||
style={{ transform: `translateX(-${100 - (value ?? 0)}%)` }} | ||
> | ||
<ProgressPrimitive.Indicator | ||
className={cn('h-full w-full ', className)} | ||
/> | ||
</View> | ||
) | ||
} | ||
|
||
return ( | ||
<ProgressPrimitive.Indicator asChild> | ||
<Animated.View | ||
style={indicator} | ||
className={cn('h-full bg-foreground', className)} | ||
/> | ||
</ProgressPrimitive.Indicator> | ||
) | ||
} |
Oops, something went wrong.