Skip to content

Commit 77df1ef

Browse files
committed
ProfileEditImage done without backend logic
1 parent 54b42bf commit 77df1ef

9 files changed

Lines changed: 168 additions & 21 deletions

File tree

src/components/screens/profile/ProfileControlledInput.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { ControlledField } from '@baca/components'
22
import { isWeb } from '@baca/constants'
3-
import { Box } from '@baca/design-system'
3+
import { Box, Text } from '@baca/design-system'
44
import { useWeb } from '@baca/hooks'
55
import { ProfileControlledInputProps } from '@baca/types/ProfileInputProps'
6+
import { StyleSheet } from 'react-native'
67

78
export const ProfileControlledInput = ({
89
label,
@@ -23,9 +24,9 @@ export const ProfileControlledInput = ({
2324
mb={isWeb ? 10 : 0}
2425
maxW={800}
2526
>
26-
{/* <Text.SmBold flex={1} color="text.primary">
27+
<Text.SmBold flex={1} color="text.primary" style={s.labelMargin}>
2728
{label}
28-
</Text.SmBold> */}
29+
</Text.SmBold>
2930
<Box flex={isWeb ? 2 : 0}>
3031
<ControlledField.Input
3132
control={control}
@@ -38,9 +39,12 @@ export const ProfileControlledInput = ({
3839
isDisabled={isDisabled}
3940
onFocus={onFocus}
4041
onSubmitEditing={onSubmitEditing}
41-
{...(!isWeb && { label })}
4242
/>
4343
</Box>
4444
</Box>
4545
)
4646
}
47+
48+
const s = StyleSheet.create({
49+
labelMargin: { marginBottom: 10 },
50+
})

src/components/screens/profile/ProfileEditImage.tsx

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { Box, Text, Button, Row } from '@baca/design-system'
1+
import { isWeb } from '@baca/constants'
2+
import { Box, Text, Button, Row, themeColors } from '@baca/design-system'
23
import * as ImagePicker from 'expo-image-picker'
34
import { t } from 'i18next'
45
import React from 'react'
5-
import { View, Image, StyleSheet } from 'react-native'
6+
import { Image, StyleSheet } from 'react-native'
67

78
export const ProfileEditImage: React.FC = () => {
89
const [image, setImage] = React.useState<string | null>(null)
@@ -21,20 +22,20 @@ export const ProfileEditImage: React.FC = () => {
2122
}
2223

2324
return (
24-
<Box borderColor="border.secondary" borderTopWidth={1} py={6} /* mb={isWeb ? 10 : 4} */>
25-
<Box style={styles.marginBottom}>
25+
<Box borderColor="border.secondary" borderTopWidth={1} py={6}>
26+
<Box style={s.marginBottom}>
2627
<Text.SmBold color="text.primary">{t('profile_screen.your_photo')}</Text.SmBold>
2728
<Text.SmRegular color="text.secondary">
2829
{t('profile_screen.your_photo_description')}
2930
</Text.SmRegular>
3031
</Box>
31-
<Box style={styles.imageContainer}>
32+
<Box style={s.imageContainer}>
3233
{image ? (
33-
<Image source={{ uri: image }} style={styles.image} />
34+
<Image source={{ uri: image }} style={s.image} />
3435
) : (
35-
<View style={styles.placeholder}>
36-
<Text style={styles.placeholderText}>No Image</Text>
37-
</View>
36+
<Box style={s.placeholder}>
37+
<Text color="Gray modern.600">{t('profile_screen.photo_innerText')}</Text>
38+
</Box>
3839
)}
3940
</Box>
4041
<Row maxW={800} justifyContent="flex-end">
@@ -44,7 +45,7 @@ export const ProfileEditImage: React.FC = () => {
4445
)
4546
}
4647

47-
const styles = StyleSheet.create({
48+
const s = StyleSheet.create({
4849
image: {
4950
height: '100%',
5051
width: '100%',
@@ -55,19 +56,17 @@ const styles = StyleSheet.create({
5556
height: 100,
5657
marginBottom: 10,
5758
overflow: 'hidden',
59+
right: isWeb ? 150 : 0,
5860
width: 100,
5961
},
6062
marginBottom: {
6163
marginBottom: 10,
6264
},
6365
placeholder: {
6466
alignItems: 'center',
67+
backgroundColor: themeColors.primitives['Gray neutral']['50'],
6568
height: '100%',
6669
justifyContent: 'center',
6770
width: '100%',
68-
// backgroundColor: '#e0e0e0',
69-
},
70-
placeholderText: {
71-
// color: '#888',
7271
},
7372
})

src/components/screens/profile/ProfilePasswordForm.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Box, Button, Row } from '@baca/design-system'
22
import { useUpdatePasswordForm } from '@baca/hooks/forms/useUpdatePasswordForm'
3-
import React from 'react'
43
import { useTranslation } from 'react-i18next'
54

65
import { ProfileControlledInput } from './ProfileControlledInput'
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { useAuthControllerUpdate } from '@baca/api/query/auth/auth'
2+
import { AuthUpdateDto } from '@baca/api/types'
3+
import { handleFormError, hapticImpact, showSuccessToast } from '@baca/utils'
4+
import { useMemo } from 'react'
5+
import { useForm } from 'react-hook-form'
6+
import { useTranslation } from 'react-i18next'
7+
8+
export const useUpdatePasswordForm = () => {
9+
const { t } = useTranslation()
10+
const { mutate: updatePasswordMutation, isLoading } = useAuthControllerUpdate()
11+
12+
const defaultValues: AuthUpdateDto = useMemo(
13+
() => ({
14+
oldPassword: '',
15+
password: '',
16+
}),
17+
[]
18+
)
19+
20+
const {
21+
control,
22+
formState: { errors },
23+
handleSubmit,
24+
reset,
25+
setError: setFormError,
26+
} = useForm<AuthUpdateDto>({
27+
mode: 'onTouched',
28+
defaultValues,
29+
})
30+
31+
const onSubmit = (data: AuthUpdateDto) => {
32+
updatePasswordMutation(
33+
{ data },
34+
{
35+
onSuccess: () => {
36+
showSuccessToast({ description: t('toast.success.profile_updated') })
37+
reset(defaultValues)
38+
},
39+
onError: (e) => {
40+
handleFormError<keyof AuthUpdateDto>(
41+
e as unknown as keyof AuthUpdateDto,
42+
({ field, description }) => {
43+
setFormError(field, { message: description })
44+
}
45+
)
46+
hapticImpact()
47+
},
48+
}
49+
)
50+
}
51+
52+
return {
53+
control,
54+
errors,
55+
isSubmitting: isLoading,
56+
submit: handleSubmit(onSubmit),
57+
}
58+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { useAuthControllerUpdate } from '@baca/api/query/auth/auth'
2+
import { AuthUpdateDto } from '@baca/api/types'
3+
import { handleFormError, hapticImpact, showSuccessToast } from '@baca/utils'
4+
import { useMemo } from 'react'
5+
import { useForm } from 'react-hook-form'
6+
import { useTranslation } from 'react-i18next'
7+
8+
export const useUpdatePasswordForm = () => {
9+
const { t } = useTranslation()
10+
const { mutate: updatePasswordMutation, isLoading } = useAuthControllerUpdate()
11+
12+
const defaultValues: AuthUpdateDto = useMemo(
13+
() => ({
14+
oldPassword: '',
15+
password: '',
16+
}),
17+
[]
18+
)
19+
20+
const {
21+
control,
22+
formState: { errors },
23+
handleSubmit,
24+
reset,
25+
setError: setFormError,
26+
} = useForm<AuthUpdateDto>({
27+
mode: 'onTouched',
28+
defaultValues,
29+
})
30+
31+
const onSubmit = (data: AuthUpdateDto) => {
32+
updatePasswordMutation(
33+
{ data },
34+
{
35+
onSuccess: () => {
36+
showSuccessToast({ description: t('toast.success.profile_updated') })
37+
reset(defaultValues)
38+
},
39+
onError: (e) => {
40+
handleFormError<keyof AuthUpdateDto>(
41+
e as unknown as keyof AuthUpdateDto,
42+
({ field, description }) => {
43+
setFormError(field, { message: description })
44+
}
45+
)
46+
hapticImpact()
47+
},
48+
}
49+
)
50+
}
51+
52+
return {
53+
control,
54+
errors,
55+
isSubmitting: isLoading,
56+
submit: handleSubmit(onSubmit),
57+
}
58+
}

src/i18n/translations/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,8 @@
242242
"are_you_sure": "Are you sure?",
243243
"remove_account_desc": "This action cannot be undone.\n\nYou will lose access to your account. If you have an active subscription you will lose access to it.\n\nPlease make sure you are certain about this action.",
244244
"your_photo": "Your photo",
245-
"your_photo_description": "This will be displayed on your profile."
245+
"your_photo_description": "This will be displayed on your profile.",
246+
"photo_innerText": "No Image"
246247
},
247248
"sign_in_screen": {
248249
"do_not_have_an_account": "Don't have an account?",

src/i18n/translations/pl.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"remove": "Usuń",
2929
"save": "Zapisz",
3030
"change": "Zmień",
31+
"upload": "Prześlij",
3132
"search": "Szukaj",
3233
"try_again_later": "Proszę spróbuj ponownie później",
3334
"try_again": "Spróbuj ponownie"
@@ -238,7 +239,10 @@
238239
"update_your_details": "Zaktualizuj swoje dane osobowe tutaj.",
239240
"remove_account": "Usuń konto",
240241
"are_you_sure": "Jesteś pewny/a?",
241-
"remove_account_desc": "Tej akcji nie można cofnąć.\n\nUtracisz dostęp do swojego konta. Jeśli masz aktywną subskrypcję, utracisz do niej dostęp.\n\nUpewnij się, że jesteś pewien tej akcji"
242+
"remove_account_desc": "Tej akcji nie można cofnąć.\n\nUtracisz dostęp do swojego konta. Jeśli masz aktywną subskrypcję, utracisz do niej dostęp.\n\nUpewnij się, że jesteś pewien tej akcji",
243+
"your_photo": "Twoje zdjęcie",
244+
"your_photo_description": "To będzie wyświetlane na twoim profilu.",
245+
"photo_innerText": "Bez Zdjęcia"
242246
},
243247
"sign_in_screen": {
244248
"do_not_have_an_account": "Nie masz konta?",

src/types/ProfileInputProps 2.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Control, FieldErrors } from 'react-hook-form'
2+
3+
export type ProfileControlledInputProps = {
4+
label: string
5+
name: string
6+
placeholder: string
7+
control: Control
8+
errors: FieldErrors
9+
isDisabled?: boolean
10+
onFocus?: () => void
11+
onSubmitEditing?: () => void
12+
}

src/types/ProfileInputProps 3.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Control, FieldErrors } from 'react-hook-form'
2+
3+
export type ProfileControlledInputProps = {
4+
label: string
5+
name: string
6+
placeholder: string
7+
control: Control
8+
errors: FieldErrors
9+
isDisabled?: boolean
10+
onFocus?: () => void
11+
onSubmitEditing?: () => void
12+
}

0 commit comments

Comments
 (0)