Skip to content
This repository has been archived by the owner on Apr 14, 2024. It is now read-only.

Commit

Permalink
Add telegram (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
VictoriaBorovskaya authored Mar 31, 2024
1 parent 704ad68 commit 16ed462
Show file tree
Hide file tree
Showing 6 changed files with 224 additions and 2 deletions.
19 changes: 19 additions & 0 deletions src/features/user/update-user/UpdateUser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,15 @@ export function UpdateUser({
dirtyFields.about ||
dirtyFields.first_name ||
dirtyFields.last_name ||
dirtyFields.telegram ||
dirtyFields.specs
) {
const updatedUser = {
id: user.id,
first_name: data.first_name,
last_name: data.last_name,
about: data.about || '',
telegram: data.telegram,
main_specialization_id: data.specs[0] ?? null,
secondary_specialization_id: data.specs[1] ?? null,
};
Expand Down Expand Up @@ -230,6 +232,23 @@ export function UpdateUser({
<FormErrorMessage>{errors.last_name?.message}</FormErrorMessage>
</Flex>
</FormControl>
<FormControl isRequired isInvalid={!!errors.last_name}>
<Flex direction="column" gap={4}>
<FormLabel mb={0}>Telegram</FormLabel>
<Input
placeholder="Ваш telegram"
py={4}
px={5}
bg="white"
borderRadius="full"
{...register('telegram', {
required: 'Обязательное поле',
minLength: { value: 2, message: 'Введите минимум 2 символа' },
})}
/>
<FormErrorMessage>{errors.telegram?.message}</FormErrorMessage>
</Flex>
</FormControl>
<FormControl>
<Flex direction="column" gap={4}>
<FormLabel mb={0}>О себе</FormLabel>
Expand Down
1 change: 1 addition & 0 deletions src/features/user/update-user/model/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface UserTypeForm {
main_specialization_id: string;
secondary_specialization_id: string;
email: string;
telegram: string;
skills: SelectOptions[];
avatar: FileList;
specs: string[];
Expand Down
174 changes: 174 additions & 0 deletions src/shared/api/types/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ export interface paths {
/** Logout */
delete: operations['logout_api_rest_auth_logout_delete'];
};
'/api/rest/auth/signup': {
/** Sign Up */
post: operations['sign_up_api_rest_auth_signup_post'];
};
'/api/rest/auth/signin': {
/** Sign In */
post: operations['sign_in_api_rest_auth_signin_post'];
};
'/api/rest/auth/oauth2/habr/authorize': {
/** Authorize */
get: operations['authorize_api_rest_auth_oauth2_habr_authorize_get'];
Expand All @@ -24,6 +32,14 @@ export interface paths {
/** Callback */
get: operations['callback_api_rest_auth_oauth2_habr_callback_get'];
};
'/api/rest/auth/change-password': {
/** Change Password */
post: operations['change_password_api_rest_auth_change_password_post'];
};
'/api/rest/auth/reset-password': {
/** Reset Password Request */
post: operations['reset_password_request_api_rest_auth_reset_password_post'];
};
'/api/rest/users/{user_id}': {
/** Get User */
get: operations['get_user_api_rest_users__user_id__get'];
Expand All @@ -50,6 +66,16 @@ export type webhooks = Record<string, never>;

export interface components {
schemas: {
/** AuthorizeRequest */
AuthorizeRequest: {
/**
* Email
* Format: email
*/
email: string;
/** Password */
password: string;
};
/** AuthorizeResponse */
AuthorizeResponse: {
user: components['schemas']['UserResponse'];
Expand All @@ -66,6 +92,18 @@ export interface components {
*/
avatar: string;
};
/** ChangePasswordRequest */
ChangePasswordRequest: {
/** Code */
code: string;
/**
* Email
* Format: email
*/
email: string;
/** New Password */
new_password: string;
};
/** HTTPValidationError */
HTTPValidationError: {
/** Detail */
Expand All @@ -88,6 +126,14 @@ export interface components {
/** Is Activated */
is_activated: boolean;
};
/** ResetPasswordRequest */
ResetPasswordRequest: {
/**
* Email
* Format: email
*/
email: string;
};
/** UserResponse */
UserResponse: {
/**
Expand All @@ -97,6 +143,8 @@ export interface components {
id: string;
/** Email */
email: string | null;
/** Telegram */
telegram: string | null;
/** First Name */
first_name: string | null;
/** Last Name */
Expand Down Expand Up @@ -130,6 +178,8 @@ export interface components {
last_name: string;
/** About */
about: string | null;
/** Telegram */
telegram: string | null;
/** Main Specialization Id */
main_specialization_id: string | null;
/** Secondary Specialization Id */
Expand Down Expand Up @@ -220,6 +270,68 @@ export interface operations {
};
};
};
/** Sign Up */
sign_up_api_rest_auth_signup_post: {
parameters: {
header?: {
Authorization?: string | null;
};
cookie?: {
access_token?: string | null;
refresh_token?: string | null;
};
};
requestBody: {
content: {
'application/json': components['schemas']['AuthorizeRequest'];
};
};
responses: {
/** @description Successful Response */
200: {
content: {
'application/json': components['schemas']['AuthorizeResponse'];
};
};
/** @description Validation Error */
422: {
content: {
'application/json': components['schemas']['HTTPValidationError'];
};
};
};
};
/** Sign In */
sign_in_api_rest_auth_signin_post: {
parameters: {
header?: {
Authorization?: string | null;
};
cookie?: {
access_token?: string | null;
refresh_token?: string | null;
};
};
requestBody: {
content: {
'application/json': components['schemas']['AuthorizeRequest'];
};
};
responses: {
/** @description Successful Response */
200: {
content: {
'application/json': unknown;
};
};
/** @description Validation Error */
422: {
content: {
'application/json': components['schemas']['HTTPValidationError'];
};
};
};
};
/** Authorize */
authorize_api_rest_auth_oauth2_habr_authorize_get: {
parameters: {
Expand Down Expand Up @@ -277,6 +389,68 @@ export interface operations {
};
};
};
/** Change Password */
change_password_api_rest_auth_change_password_post: {
parameters: {
header?: {
Authorization?: string | null;
};
cookie?: {
access_token?: string | null;
refresh_token?: string | null;
};
};
requestBody: {
content: {
'application/json': components['schemas']['ChangePasswordRequest'];
};
};
responses: {
/** @description Successful Response */
200: {
content: {
'application/json': unknown;
};
};
/** @description Validation Error */
422: {
content: {
'application/json': components['schemas']['HTTPValidationError'];
};
};
};
};
/** Reset Password Request */
reset_password_request_api_rest_auth_reset_password_post: {
parameters: {
header?: {
Authorization?: string | null;
};
cookie?: {
access_token?: string | null;
refresh_token?: string | null;
};
};
requestBody: {
content: {
'application/json': components['schemas']['ResetPasswordRequest'];
};
};
responses: {
/** @description Successful Response */
200: {
content: {
'application/json': unknown;
};
};
/** @description Validation Error */
422: {
content: {
'application/json': components['schemas']['HTTPValidationError'];
};
};
};
};
/** Get User */
get_user_api_rest_users__user_id__get: {
parameters: {
Expand Down
9 changes: 8 additions & 1 deletion src/widgets/onboarding/Onboarding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const defaultUser = {
last_name: '',
avatar: null,
about: null,
telegram: '',
main_specialization_id: null,
secondary_specialization_id: null,
specs: [],
Expand All @@ -49,6 +50,7 @@ export function Onboarding({ userId }: OnboardingProps) {
const [previewImg, setPrevievImg] = useState('');
const [isNameFilled, setIsNameFilled] = useState(false);
const [isLastNameFilled, setIsLastNameFilled] = useState(false);
const [isTelegramFilled, setIsTelegramFilled] = useState(false);
const [isAdding, setIsAdding] = useState(false);

const { mutate: mutateUser, data: result } = useUpdateProfile();
Expand Down Expand Up @@ -80,6 +82,7 @@ export function Onboarding({ userId }: OnboardingProps) {
first_name: data.first_name,
last_name: data.last_name,
about: data.about,
telegram: data.telegram,
main_specialization_id: data.specs[0] ?? null,
secondary_specialization_id: data.specs[1] ?? null,
};
Expand Down Expand Up @@ -151,6 +154,7 @@ export function Onboarding({ userId }: OnboardingProps) {
form={form}
setIsNameFilled={setIsNameFilled}
setIsLastNameFilled={setIsLastNameFilled}
setIsTelegramFilled={setIsTelegramFilled}
/>
</TabPanel>
<TabPanel>
Expand All @@ -177,7 +181,10 @@ export function Onboarding({ userId }: OnboardingProps) {
{tabIndex < 3 && (
<Button
w="full"
isDisabled={tabIndex === 1 && (!isNameFilled || !isLastNameFilled)}
isDisabled={
tabIndex === 1 &&
(!isNameFilled || !isLastNameFilled || !isTelegramFilled)
}
onClick={() => {
handleTabsChange(tabIndex + 1);
}}
Expand Down
1 change: 1 addition & 0 deletions src/widgets/onboarding/Onboarding.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface CreateUserType {
last_name: string;
avatar: FileList | null;
about: string | null;
telegram: string;
main_specialization_id: string | null;
secondary_specialization_id: string | null;
specs: string[];
Expand Down
22 changes: 21 additions & 1 deletion src/widgets/onboarding/tabs/name/NameTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ interface NameTabsProps {
form: ReturnType<typeof useForm<CreateUserType>>;
setIsNameFilled: (isNameFilled: boolean) => void;
setIsLastNameFilled: (isLastNameFilled: boolean) => void;
setIsTelegramFilled: (isTelegramFilled: boolean) => void;
}

export function NameTabs(props: NameTabsProps) {
const { setIsNameFilled, setIsLastNameFilled } = props;
const { setIsNameFilled, setIsLastNameFilled, setIsTelegramFilled } = props;
const {
register,
formState: { errors },
Expand Down Expand Up @@ -69,6 +70,25 @@ export function NameTabs(props: NameTabsProps) {
/>
<FormErrorMessage>{errors.last_name?.message}</FormErrorMessage>
</FormControl>
<FormControl isInvalid={!!errors.last_name} isRequired>
<Input
placeholder="Ваш telegram*"
py={4}
px={5}
bg="white"
borderRadius="full"
{...register('telegram', {
required: 'Обязательное поле',
minLength: { value: 2, message: 'Введите минимум 2 символа' },
onChange: (e: ChangeEvent<HTMLInputElement>) => {
if (e.target.value && e.target.value.length > 3) {
setIsTelegramFilled(true);
}
},
})}
/>
<FormErrorMessage>{errors.telegram?.message}</FormErrorMessage>
</FormControl>
</Stack>
</Stack>
);
Expand Down

0 comments on commit 16ed462

Please sign in to comment.