Browse Source

Merge branch 'contacts-fullname' into 'master'

CHANGE | Show user first, middle and last name on contacts list, contact detail and profile screens

See merge request jetup/rws/rws-appication!362
merge-requests/363/merge
Coder 2 years ago
parent
commit
8f33a03cdd
  1. 10
      src/modules/account/atoms/account-title.atom.tsx
  2. 5
      src/modules/account/hooks/use-account-editor.hook.ts
  3. 4
      src/modules/account/screens/account.screen.tsx
  4. 4
      src/modules/account/validations/edit-account.validator.ts
  5. 8
      src/modules/contacts/hooks/use-contact-detail.hook.ts
  6. 4
      src/modules/contacts/hooks/use-fetch-contacts.hook.ts
  7. 30
      src/modules/contacts/screens/contact-detail.screen.tsx
  8. 3
      src/shared/enums/exception-keys.enum.ts
  9. 3
      src/shared/helpers/exceptions.helpers.ts
  10. 4
      src/shared/helpers/name.helpers.ts
  11. 3
      src/shared/interfaces/contact.interfaces.ts

10
src/modules/account/atoms/account-title.atom.tsx

@ -4,9 +4,11 @@ import { $size, isAndroid, Txt } from '@/shared' @@ -4,9 +4,11 @@ import { $size, isAndroid, Txt } from '@/shared'
import { StyleSheet, View } from 'react-native'
import { PartialTheme } from '@/shared/themes/interfaces'
import { useTheme } from '@/shared/hooks/use-theme.hook'
import { createContactName } from '@/shared/helpers'
interface IAccountTitleAtomProps {
firstName: string
middleName: string
lastName: string
position: string
myFactoryName?: string
@ -24,7 +26,11 @@ export const AccountTitleAtom = (props: IAccountTitleAtomProps) => { @@ -24,7 +26,11 @@ export const AccountTitleAtom = (props: IAccountTitleAtomProps) => {
return (
<View style={styles.titleWrap}>
<Txt style={styles.title}>
{`${props.firstName || ''} ${props.lastName || ''}`}
{createContactName(
props.firstName,
props.middleName,
props.lastName,
)}
</Txt>
<Txt style={styles.description}>{getSubText()}</Txt>
</View>
@ -43,6 +49,8 @@ const createStyles = (theme: PartialTheme) => @@ -43,6 +49,8 @@ const createStyles = (theme: PartialTheme) =>
fontSize: $size(22, 20),
fontWeight: isAndroid('500', '400'),
marginBottom: $size(5, 5),
textAlign: 'center',
lineHeight: $size(28, 24),
},
description: {
color: theme.$secondaryText,

5
src/modules/account/hooks/use-account-editor.hook.ts

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
import { accountManagerInstance as accountManager } from '@/managers'
import { accountService } from '@/services/domain'
import { appEvents, IFile, useForm } from '@/shared'
import { appEvents, getMessageByExceptionKey, IFile, useForm } from '@/shared'
import { selectAccount } from '@/store/account'
import * as _ from 'lodash'
import { useCallback, useEffect, useState } from 'react'
@ -128,9 +128,10 @@ export const useAccountEditor = () => { @@ -128,9 +128,10 @@ export const useAccountEditor = () => {
onPressOk: () => {},
})
} catch (e: any) {
const message = e.response?.data?.key ? getMessageByExceptionKey(e.response?.data?.key) : 'Спробуйте будь-ласка пізніше.'
appEvents.emit('openInfoModal', {
title: 'Сталась помилка!',
message: 'Спробуйте будь-ласка пізніше.',
message,
onPressOk: () => {},
})
} finally {

4
src/modules/account/screens/account.screen.tsx

@ -95,6 +95,7 @@ export const AccountScreen: FC<IProps> = ({ navigation }) => { @@ -95,6 +95,7 @@ export const AccountScreen: FC<IProps> = ({ navigation }) => {
<AccountTitleAtom
firstName={values.firstName}
middleName={values.middleName}
lastName={values.lastName}
position={values.position}
myFactoryName={myFactoryName}
@ -157,6 +158,9 @@ export const AccountScreen: FC<IProps> = ({ navigation }) => { @@ -157,6 +158,9 @@ export const AccountScreen: FC<IProps> = ({ navigation }) => {
onChange={v => setFormField('innerPhoneNumber', v)}
keybordType="phone-pad"
error={errors.innerPhoneNumber}
inputProps={{
maxLength: 6,
}}
/>
<TextInputWithIcon

4
src/modules/account/validations/edit-account.validator.ts

@ -58,13 +58,13 @@ const constraints = { @@ -58,13 +58,13 @@ const constraints = {
// presence: presenceCost,
length: {
minimum: 12,
message: '^Номер не валідний',
message: '^Номер не вірний',
},
},
email: {
presence: presenceCost,
email: {
message: '^Введений email не валідний',
message: '^Введений email не вірний',
},
},
dateOfBirth: {

8
src/modules/contacts/hooks/use-contact-detail.hook.ts

@ -2,7 +2,7 @@ import { appEvents, hasImageUrl, IContactDetail } from '@/shared' @@ -2,7 +2,7 @@ import { appEvents, hasImageUrl, IContactDetail } from '@/shared'
import { contactsService } from '@/services/domain'
import { useEffect, useMemo, useState } from 'react'
import { getContactDetailConfig } from '../configs'
import { createFullName, isSoonBirthday } from '@/shared/helpers'
import { createContactName, isSoonBirthday } from '@/shared/helpers'
import { Linking } from 'react-native'
import { ContactDetailFieldType } from '../enums'
import moment from 'moment'
@ -43,10 +43,7 @@ export const useContactDetail = (id: number) => { @@ -43,10 +43,7 @@ export const useContactDetail = (id: number) => {
userId: contactDetailInfo?.userId,
firstName: contactDetailInfo.firstName,
lastName: contactDetailInfo?.lastName,
fullName: createFullName(
contactDetailInfo.firstName,
contactDetailInfo?.lastName,
),
fullName: createContactName(contactDetailInfo.firstName, contactDetailInfo.middleName, contactDetailInfo.lastName),
position: contactDetailInfo?.position,
factoryName: contactDetail?.factoryName,
avatarUrl: hasImageUrl(
@ -60,6 +57,7 @@ export const useContactDetail = (id: number) => { @@ -60,6 +57,7 @@ export const useContactDetail = (id: number) => {
isSoonBirthday: isSoonBirthday(contactDetailInfo?.dateOfBirth),
email: contactDetail?.email,
chatId: contactDetail?.chatId,
status: contactDetail?.status
}
}
}, [contactDetail])

4
src/modules/contacts/hooks/use-fetch-contacts.hook.ts

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
import { createFullName, isSoonBirthday } from '@/shared/helpers'
import { createContactName, isSoonBirthday } from '@/shared/helpers'
import { useEffect, useState } from 'react'
import { IContact, useFlatList, useSocketListener } from '@/shared'
import { contactsService } from '@/services/domain'
@ -27,7 +27,7 @@ export const useFetchContacts = () => { @@ -27,7 +27,7 @@ export const useFetchContacts = () => {
items.map((it: IContact) => {
return {
userId: it.userId,
fullName: createFullName(it.firstName, it.lastName),
fullName: createContactName(it.firstName, it.middleName, it.lastName),
isSoonBirthday: isSoonBirthday(it.dateOfBirth),
avatarUrl: it.avatarUrl,
}

30
src/modules/contacts/screens/contact-detail.screen.tsx

@ -4,6 +4,7 @@ import { @@ -4,6 +4,7 @@ import {
$size,
appEvents,
AvatarTitle,
EUserStatus,
IRouteParams,
RouteKey,
ScreenLayout,
@ -67,7 +68,10 @@ export const ContactDetailScreen: FC<IProps> = ({ navigation, route }) => { @@ -67,7 +68,10 @@ export const ContactDetailScreen: FC<IProps> = ({ navigation, route }) => {
{...it}
key={`${it.value}---${i}`}
disabled={type === ContactDetailFieldType.OTHER}
onPress={() => onPress(type, it.value)}
onPress={() => {
if (contact?.status !== EUserStatus.Deleted && it.value)
onPress(type, it.value)
}}
/>
)),
[contact],
@ -108,16 +112,18 @@ export const ContactDetailScreen: FC<IProps> = ({ navigation, route }) => { @@ -108,16 +112,18 @@ export const ContactDetailScreen: FC<IProps> = ({ navigation, route }) => {
style={styles.avatarContainer}
/>
<ContactsSpeakings
contactId={contactId}
onCall={() =>
Alert.alert(
'ця функція буде реалізована в наступній версії додатку',
)
}
onMessage={onPressMessage}
disabled={contact?.userId === accountId}
/>
{contact?.status !== EUserStatus.Deleted && (
<ContactsSpeakings
contactId={contactId}
onCall={() =>
Alert.alert(
'ця функція буде реалізована в наступній версії додатку',
)
}
onMessage={onPressMessage}
disabled={contact?.userId === accountId}
/>
)}
{fieldsToRender}
</View>
@ -133,6 +139,8 @@ const createStyles = (theme: PartialTheme) => @@ -133,6 +139,8 @@ const createStyles = (theme: PartialTheme) =>
},
avatarTitle: {
fontSize: $size(22, 20),
textAlign: 'center',
lineHeight: $size(28, 24),
},
avatarContainer: {
marginBottom: $size(20, 18),

3
src/shared/enums/exception-keys.enum.ts

@ -4,4 +4,7 @@ export enum ExceptionKeys { @@ -4,4 +4,7 @@ export enum ExceptionKeys {
WrongCode = 'wrong_code',
NotFound = 'not_found',
Forbidden = 'forbidden_resource',
PhoneNumberExist = 'phone_number_exist',
PersonalPhoneNumberExist = 'personal_phone_number_exist',
EmailExist = 'email_exist'
}

3
src/shared/helpers/exceptions.helpers.ts

@ -5,6 +5,9 @@ const exceptionsDictionary = { @@ -5,6 +5,9 @@ const exceptionsDictionary = {
[ExceptionKeys.InvalidCredentials]: 'Невірно введені дані',
[ExceptionKeys.Forbidden]:
'Вашу IP-адресу заблоковано. Для розблокування зверніться до адміністратора',
[ExceptionKeys.PhoneNumberExist]: 'Вказаний робочий телефон вже зайнятий',
[ExceptionKeys.PersonalPhoneNumberExist]: 'Вказаний персональний телефон вже зайнятий',
[ExceptionKeys.EmailExist]: 'Вказана електронна пошта вже зайнята'
}
export const getMessageByExceptionKey = (key: ExceptionKeys) => {

4
src/shared/helpers/name.helpers.ts

@ -1,3 +1,7 @@ @@ -1,3 +1,7 @@
export const createFullName = (firstName: string, lastName: string) => {
return [firstName, lastName].filter(it => it).join(' ')
}
export const createContactName = (firstName?: string, middleName?: string, lastName?: string) => {
return [lastName, firstName, middleName].filter(it => it).join(' ')
}

3
src/shared/interfaces/contact.interfaces.ts

@ -1,3 +1,5 @@ @@ -1,3 +1,5 @@
import { EUserStatus } from "../enums"
export interface IContact {
userId: number
firstName: string
@ -10,6 +12,7 @@ export interface IContact { @@ -10,6 +12,7 @@ export interface IContact {
export interface IContactDetail {
id: number
phoneNumber: string
status: EUserStatus
email: string
factoryName?: string
chatId: number

Loading…
Cancel
Save