mirror of
https://github.com/sergeyyarkov/educt-client.git
synced 2026-10-11 10:19:22 +03:00
fix: fixed contacts updating
This commit is contained in:
parent
d133b69982
commit
f8ae2107eb
@ -1,8 +1,9 @@
|
|||||||
import React, { useState } from 'react';
|
import React from 'react';
|
||||||
|
import * as helpers from '@educt/helpers';
|
||||||
import { observer } from 'mobx-react';
|
import { observer } from 'mobx-react';
|
||||||
import { SubmitHandler, useForm } from 'react-hook-form';
|
import { SubmitHandler, useForm } from 'react-hook-form';
|
||||||
import { MdSave } from 'react-icons/md';
|
import { MdSave } from 'react-icons/md';
|
||||||
import { Text, Input, Button } from '@chakra-ui/react';
|
import { Text, Input } from '@chakra-ui/react';
|
||||||
import { Box, Stack } from '@chakra-ui/layout';
|
import { Box, Stack } from '@chakra-ui/layout';
|
||||||
import { FormControl, FormHelperText } from '@chakra-ui/form-control';
|
import { FormControl, FormHelperText } from '@chakra-ui/form-control';
|
||||||
import { yupResolver } from '@hookform/resolvers/yup';
|
import { yupResolver } from '@hookform/resolvers/yup';
|
||||||
@ -15,6 +16,7 @@ import { IUserContacts } from '@educt/interfaces';
|
|||||||
/**
|
/**
|
||||||
* Hooks
|
* Hooks
|
||||||
*/
|
*/
|
||||||
|
import { useState } from 'react';
|
||||||
import { useToast } from '@chakra-ui/toast';
|
import { useToast } from '@chakra-ui/toast';
|
||||||
import { useRootStore } from '@educt/hooks/useRootStore';
|
import { useRootStore } from '@educt/hooks/useRootStore';
|
||||||
import { useErrorHandler } from 'react-error-boundary';
|
import { useErrorHandler } from 'react-error-boundary';
|
||||||
@ -62,7 +64,8 @@ const UpdateUserContactsForm: React.FC<UpdateUserContactsFormPropsType> = ({ con
|
|||||||
const onSubmit: SubmitHandler<UpdateUserContactsInputType> = async data => {
|
const onSubmit: SubmitHandler<UpdateUserContactsInputType> = async data => {
|
||||||
try {
|
try {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
await userStore.updateCurrentUserContacts(data);
|
const updatedFields = helpers.getDirtyFields(dirtyFields, data);
|
||||||
|
await userStore.updateCurrentUserContacts(updatedFields);
|
||||||
toast({ title: 'Contacts saved!', status: 'info' });
|
toast({ title: 'Contacts saved!', status: 'info' });
|
||||||
reset({
|
reset({
|
||||||
phone_number: data.phone_number ?? '',
|
phone_number: data.phone_number ?? '',
|
||||||
@ -113,7 +116,7 @@ const UpdateUserContactsForm: React.FC<UpdateUserContactsFormPropsType> = ({ con
|
|||||||
type='text'
|
type='text'
|
||||||
size='md'
|
size='md'
|
||||||
variant='flushed'
|
variant='flushed'
|
||||||
placeholder='@tw_username'
|
placeholder='@username'
|
||||||
isInvalid={errors.twitter_id ? true : false}
|
isInvalid={errors.twitter_id ? true : false}
|
||||||
{...register('twitter_id')}
|
{...register('twitter_id')}
|
||||||
/>
|
/>
|
||||||
@ -128,7 +131,7 @@ const UpdateUserContactsForm: React.FC<UpdateUserContactsFormPropsType> = ({ con
|
|||||||
type='text'
|
type='text'
|
||||||
size='md'
|
size='md'
|
||||||
variant='flushed'
|
variant='flushed'
|
||||||
placeholder='@tg_username'
|
placeholder='@username'
|
||||||
isInvalid={errors.telegram_id ? true : false}
|
isInvalid={errors.telegram_id ? true : false}
|
||||||
{...register('telegram_id')}
|
{...register('telegram_id')}
|
||||||
/>
|
/>
|
||||||
@ -143,7 +146,7 @@ const UpdateUserContactsForm: React.FC<UpdateUserContactsFormPropsType> = ({ con
|
|||||||
type='text'
|
type='text'
|
||||||
size='md'
|
size='md'
|
||||||
variant='flushed'
|
variant='flushed'
|
||||||
placeholder='VKontakte id'
|
placeholder='username'
|
||||||
isInvalid={errors.vk_id ? true : false}
|
isInvalid={errors.vk_id ? true : false}
|
||||||
{...register('vk_id')}
|
{...register('vk_id')}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@ -51,7 +51,7 @@ export const ProfileDescription: React.FC<IProfileDescriptionProps> = props => {
|
|||||||
const { fullname, email, roles, ...boxProps } = props;
|
const { fullname, email, roles, ...boxProps } = props;
|
||||||
return (
|
return (
|
||||||
<Box w='full' ml={{ md: '50' }} mt={{ base: '2', md: '3' }} {...boxProps}>
|
<Box w='full' ml={{ md: '50' }} mt={{ base: '2', md: '3' }} {...boxProps}>
|
||||||
<Flex alignItems='center' justifyContent='space-between'>
|
<Flex alignItems='center' justifyContent={{ base: 'center', md: 'space-between' }}>
|
||||||
<Box>
|
<Box>
|
||||||
<Heading lineHeight='1.5rem' fontWeight='bold' fontSize='24px'>
|
<Heading lineHeight='1.5rem' fontWeight='bold' fontSize='24px'>
|
||||||
{fullname}
|
{fullname}
|
||||||
|
|||||||
@ -53,7 +53,7 @@ const ProfilePage: React.FC<IPageProps> = () => {
|
|||||||
<ProfileDescription fullname={me.fullname} email={me.email} roles={me.roles} />
|
<ProfileDescription fullname={me.fullname} email={me.email} roles={me.roles} />
|
||||||
</ProfileBaseInfo>
|
</ProfileBaseInfo>
|
||||||
<PageContent>
|
<PageContent>
|
||||||
<Tabs>
|
<Tabs mt='7'>
|
||||||
<TabList>
|
<TabList>
|
||||||
<Tab>Account information</Tab>
|
<Tab>Account information</Tab>
|
||||||
<Tab>My contacts</Tab>
|
<Tab>My contacts</Tab>
|
||||||
|
|||||||
@ -2,7 +2,12 @@ import { AxiosInstance } from 'axios';
|
|||||||
import { ApiServiceInstance } from '.';
|
import { ApiServiceInstance } from '.';
|
||||||
import * as helpers from '@educt/helpers';
|
import * as helpers from '@educt/helpers';
|
||||||
import { IApiRespose, IMe, IUser, IUserContacts } from '@educt/interfaces';
|
import { IApiRespose, IMe, IUser, IUserContacts } from '@educt/interfaces';
|
||||||
import { CreateUserParamsType, FetchUsersParamsType, UpdateUserParamsType } from '@educt/types';
|
import {
|
||||||
|
CreateUserParamsType,
|
||||||
|
FetchUsersParamsType,
|
||||||
|
UpdateUserParamsType,
|
||||||
|
UpdateUserContactsParamsType,
|
||||||
|
} from '@educt/types';
|
||||||
|
|
||||||
class UserService {
|
class UserService {
|
||||||
public api: AxiosInstance;
|
public api: AxiosInstance;
|
||||||
@ -87,8 +92,8 @@ class UserService {
|
|||||||
* @param data New values for contacts
|
* @param data New values for contacts
|
||||||
* @returns Updated contacts
|
* @returns Updated contacts
|
||||||
*/
|
*/
|
||||||
public async updateContacts(data: IUserContacts): Promise<IApiRespose<IUserContacts>> {
|
public async updateContacts(data: UpdateUserContactsParamsType): Promise<IApiRespose<IUserContacts>> {
|
||||||
const result = await this.api.put('v1/me/contacts', helpers.removeEmptyValues(data));
|
const result = await this.api.patch('v1/me/contacts', data);
|
||||||
return result.data;
|
return result.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -4,8 +4,13 @@ import * as helpers from '@educt/helpers';
|
|||||||
/**
|
/**
|
||||||
* Types
|
* Types
|
||||||
*/
|
*/
|
||||||
import { CreateUserParamsType, FetchUsersParamsType, UpdateUserParamsType } from '@educt/types';
|
import {
|
||||||
import { IUser, IUserContacts, IMe, IPaginationMeta } from '@educt/interfaces';
|
CreateUserParamsType,
|
||||||
|
FetchUsersParamsType,
|
||||||
|
UpdateUserContactsParamsType,
|
||||||
|
UpdateUserParamsType,
|
||||||
|
} from '@educt/types';
|
||||||
|
import { IUser, IMe, IPaginationMeta } from '@educt/interfaces';
|
||||||
import { UserRoleEnum } from '@educt/enums';
|
import { UserRoleEnum } from '@educt/enums';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -135,7 +140,7 @@ export default class UserStore {
|
|||||||
* @param data New contacts
|
* @param data New contacts
|
||||||
* @returns Updated user contacts
|
* @returns Updated user contacts
|
||||||
*/
|
*/
|
||||||
public async updateCurrentUserContacts(data: IUserContacts) {
|
public async updateCurrentUserContacts(data: UpdateUserContactsParamsType) {
|
||||||
const result = await UserServiceInstance.updateContacts(data);
|
const result = await UserServiceInstance.updateContacts(data);
|
||||||
|
|
||||||
runInAction(() => {
|
runInAction(() => {
|
||||||
|
|||||||
6
src/types/index.d.ts
vendored
6
src/types/index.d.ts
vendored
@ -117,6 +117,12 @@ export type CreateUserParamsType = {
|
|||||||
password: string;
|
password: string;
|
||||||
};
|
};
|
||||||
export type UpdateUserParamsType = { first_name?: string; last_name?: string; email?: string };
|
export type UpdateUserParamsType = { first_name?: string; last_name?: string; email?: string };
|
||||||
|
export type UpdateUserContactsParamsType = {
|
||||||
|
phone_number?: string | null | undefined;
|
||||||
|
twitter_id?: string | null | undefined;
|
||||||
|
telegram_id?: string | null | undefined;
|
||||||
|
vk_id?: string | null | undefined;
|
||||||
|
};
|
||||||
|
|
||||||
export type CreateCourseParamsType = {
|
export type CreateCourseParamsType = {
|
||||||
title: string;
|
title: string;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user