-
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): add user default budget (#248)
![Simulator Screenshot - iPhone 15 Pro - 2024-09-01 at 19.49.33.png](https://graphite-user-uploaded-assets-prod.s3.amazonaws.com/1VEKR8FQ1Qa5iAiqVGqF/15c861e9-ae4c-4314-bbd3-0ed275f1a83c.png)
- Loading branch information
Showing
17 changed files
with
230 additions
and
72 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
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,52 @@ | ||
import { cn } from '@/lib/utils' | ||
import { useController } from 'react-hook-form' | ||
import { Text, View } from 'react-native' | ||
import { Label } from '../ui/label' | ||
import { Switch } from '../ui/switch' | ||
|
||
type BooleanFieldProps = { | ||
name: string | ||
label?: string | ||
disabled?: boolean | ||
wrapperClassName?: string | ||
className?: string | ||
} | ||
|
||
export const BooleanField = ({ | ||
name, | ||
label, | ||
className, | ||
wrapperClassName, | ||
disabled, | ||
}: BooleanFieldProps) => { | ||
const { | ||
field: { onChange, value }, | ||
fieldState, | ||
} = useController({ name }) | ||
return ( | ||
<View className={cn('gap-1', wrapperClassName)}> | ||
<View className="flex-row items-center gap-4"> | ||
{!!label && ( | ||
<Label | ||
nativeID={`label-${name}`} | ||
onPress={() => { | ||
onChange(!value) | ||
}} | ||
> | ||
{label} | ||
</Label> | ||
)} | ||
<Switch | ||
className={cn(className)} | ||
checked={value} | ||
disabled={disabled} | ||
onCheckedChange={onChange} | ||
nativeID={`label-${name}`} | ||
/> | ||
</View> | ||
{!!fieldState.error && ( | ||
<Text className="text-destructive">{fieldState.error.message}</Text> | ||
)} | ||
</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
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,30 @@ | ||
import { useUser } from '@clerk/clerk-expo' | ||
|
||
export function useUserMetadata() { | ||
const { user } = useUser() | ||
|
||
async function setOnboardedAt(onboardedAt: string | undefined) { | ||
return user?.update({ | ||
unsafeMetadata: { | ||
...(user?.unsafeMetadata ?? {}), | ||
onboardedAt, | ||
}, | ||
}) | ||
} | ||
|
||
async function setDefaultBudgetId(defaultBudgetId: string | undefined) { | ||
return user?.update({ | ||
unsafeMetadata: { | ||
...(user?.unsafeMetadata ?? {}), | ||
defaultBudgetId, | ||
}, | ||
}) | ||
} | ||
|
||
return { | ||
onboardedAt: user?.unsafeMetadata?.onboardedAt, | ||
defaultBudgetId: user?.unsafeMetadata?.defaultBudgetId, | ||
setOnboardedAt, | ||
setDefaultBudgetId, | ||
} | ||
} |
Oops, something went wrong.