diff --git a/' b/' new file mode 100644 index 0000000..0701cbe --- /dev/null +++ b/' @@ -0,0 +1,37 @@ +import { Text, View } from "react-native"; +import { useGetBrigadesQuery } from "../../api/useQuery" +import { CardBrigade } from "../CardBrigade/CardBrigade"; +import { IBrigade } from "../../type/IBirgade"; +import React, { useState } from "react"; +import { BrigadeSelectorProps } from "./type"; +import { BrigadeChooseInfo } from "../BrigadeChooseInfo/BrigadeChooseInfo"; +import { ITypePage } from "@/shared/type/ITypePage/ITypePage"; + +export const BrigadeSelector: React.FC = ({ handlerSubmit, setValue, handlerPreviousPage, stateRegister }) => { + const { data, isLoading, error } = useGetBrigadesQuery() + const [brigade, setBrigade] = useState() + const handlerChooseSubmit = async (id: string) => { + if (!id) return + setValue("brigadId", id) + handlerSubmit() + } + if (isLoading && error) { + return ( + load or error + ) + } + const handlerBrigadeInfo = (data: IBrigade) => setBrigade(data) + return ( + + {!brigade ? + data?.map((elem: IBrigade) => + handlerBrigadeInfo(elem)} /> + ) + : null + // + } + + + + ) +} diff --git "a/\\" "b/\\" new file mode 100644 index 0000000..550936c --- /dev/null +++ "b/\\" @@ -0,0 +1,44 @@ +import React, { useState } from "react"; +import { AuthForm, AuthLink } from "@/features/auth" +import { AuthTitle } from "@/features/auth/ui/AuthTitle/AuthTitle" +import { AuthProps } from "@/shared/type/AuthProps/type" +import { View, Text, StyleSheet } from "react-native" + + +function AuthText(props: { text: string }) { + return {props.text}; +} + +export const Auth: React.FC = ({ typePage }) => { + const [stateRegister, setStateRegister] = useState(false) + + + return ( + + + + + + + ) +} + +const styles = StyleSheet.create({ + subtitle: { + fontSize: 32, + fontWeight: 700, + paddingLeft: 41, + marginBottom: 26, + + + }, + back: { + backgroundColor: "rgb(216, 216, 216)", + height: 917, + } +}) + + + + + diff --git a/app/index.tsx b/app/index.tsx index d41237c..b0f772c 100644 --- a/app/index.tsx +++ b/app/index.tsx @@ -9,5 +9,6 @@ export default function HomeScreen() { } else { return } + // } diff --git a/assets/images/registration.png b/assets/images/registration.png new file mode 100644 index 0000000..75c4ad1 Binary files /dev/null and b/assets/images/registration.png differ diff --git a/src/entites/brigade/api/useQuery.ts b/src/entites/brigade/api/useQuery.ts index c345ec9..420fa22 100644 --- a/src/entites/brigade/api/useQuery.ts +++ b/src/entites/brigade/api/useQuery.ts @@ -8,6 +8,6 @@ import { IError } from "@/shared/type/Api/IError"; export const useGetBrigadesQuery = () => { return useQuery>({ queryKey: ["brigade"], - queryFn: async () => await axiosGet({ path: "/brigade/get" }), + queryFn: async () => await axiosGet({ path: "/brigade" }), }); }; diff --git a/src/entites/brigade/ui/BrigadeChooseInfo/BrigadeChooseInfo.tsx b/src/entites/brigade/ui/BrigadeChooseInfo/BrigadeChooseInfo.tsx new file mode 100644 index 0000000..fd324dd --- /dev/null +++ b/src/entites/brigade/ui/BrigadeChooseInfo/BrigadeChooseInfo.tsx @@ -0,0 +1,28 @@ +import { Image, Text, View } from "react-native" +import { BrigadeChooseInfoProps } from "./type" +import { BrigadeRequirements } from "../requirement/BrigadeRequirements/BrigadeRequirements" +import { ItemButton } from "@/shared/ui/ItemButton/ItemButton" + +export const BrigadeChooseInfo: React.FC = ({ brigade, handlerSubmit }) => { + + return ( + + + + {brigade.name} + + {brigade.description} + + handlerSubmit(brigade._id)} + /> + + + ) +} diff --git a/src/entites/brigade/ui/BrigadeChooseInfo/type.ts b/src/entites/brigade/ui/BrigadeChooseInfo/type.ts new file mode 100644 index 0000000..0a5f115 --- /dev/null +++ b/src/entites/brigade/ui/BrigadeChooseInfo/type.ts @@ -0,0 +1,9 @@ +import { IBrigade } from "../../type/IBirgade"; + + +export interface BrigadeChooseInfoProps { + brigade: IBrigade + handlerSubmit: (id: string) => void + +} + diff --git a/src/entites/brigade/ui/BrigadeSelector/BrigadeSelector.tsx b/src/entites/brigade/ui/BrigadeSelector/BrigadeSelector.tsx index 4326c3d..0fa55c6 100644 --- a/src/entites/brigade/ui/BrigadeSelector/BrigadeSelector.tsx +++ b/src/entites/brigade/ui/BrigadeSelector/BrigadeSelector.tsx @@ -2,27 +2,48 @@ import { Text, View } from "react-native"; import { useGetBrigadesQuery } from "../../api/useQuery" import { CardBrigade } from "../CardBrigade/CardBrigade"; import { IBrigade } from "../../type/IBirgade"; -import React from "react"; +import React, { useState } from "react"; import { BrigadeSelectorProps } from "./type"; +<<<<<<< HEAD +import { useNavigation } from "@react-navigation/native"; -export const BrigadeSelector: React.FC = ({ handlerSubmit, setValue }) => { +======= +import { BrigadeChooseInfo } from "../BrigadeChooseInfo/BrigadeChooseInfo"; +import { ITypePage } from "@/shared/type/ITypePage/ITypePage"; +>>>>>>> main + + +export const BrigadeSelector: React.FC = ({ handlerSubmit, setValue, stateRegister, handlerNextPage }) => { const { data, isLoading, error } = useGetBrigadesQuery() + const [brigade, setBrigade] = useState() + const handlerChooseSubmit = async (id: string) => { + if (!id) return setValue("brigadId", id) handlerSubmit() } if (isLoading && error) { return ( - er; + load or error ) } + const handlerBrigadeInfo = (data: IBrigade) => { + setBrigade(data) + handlerNextPage() + } return ( - { - data?.map((elem: IBrigade) => - handlerChooseSubmit(elem._id)} /> - ) + {stateRegister == 1 && + data?.map((elem: IBrigade) => ( + handlerBrigadeInfo(elem)} /> + )) } + {stateRegister == 2 && brigade ? ( + + ) : null} diff --git a/src/entites/brigade/ui/BrigadeSelector/type.ts b/src/entites/brigade/ui/BrigadeSelector/type.ts index a9a3c54..0145dae 100644 --- a/src/entites/brigade/ui/BrigadeSelector/type.ts +++ b/src/entites/brigade/ui/BrigadeSelector/type.ts @@ -4,4 +4,6 @@ import { UseFormSetValue } from "react-hook-form"; export interface BrigadeSelectorProps { setValue: UseFormSetValue; handlerSubmit: () => void + stateRegister: number + handlerNextPage: () => void } diff --git a/src/entites/brigade/ui/CardBrigade/CardBrigade.tsx b/src/entites/brigade/ui/CardBrigade/CardBrigade.tsx index 2b56d9a..72151e5 100644 --- a/src/entites/brigade/ui/CardBrigade/CardBrigade.tsx +++ b/src/entites/brigade/ui/CardBrigade/CardBrigade.tsx @@ -1,12 +1,32 @@ -import { Text, View } from "react-native" +import { Image, StyleSheet, Text, View } from "react-native" import { CardBrigadeProps } from "./type" import { ItemButton } from "@/shared/ui/ItemButton/ItemButton" export const CardBrigade: React.FC = ({ brigade, handler }) => { return ( - + + {brigade.name} handler(brigade._id)} /> ) } + +const styles = StyleSheet.create({ + card: { + width: 158, + height: 158 + }, + brigadeImg: { + width: 145, + height: 130 + } + +}) diff --git a/src/entites/brigade/ui/requirement/BrigadeRequirements/BrigadeRequirements.tsx b/src/entites/brigade/ui/requirement/BrigadeRequirements/BrigadeRequirements.tsx new file mode 100644 index 0000000..950b684 --- /dev/null +++ b/src/entites/brigade/ui/requirement/BrigadeRequirements/BrigadeRequirements.tsx @@ -0,0 +1,15 @@ +import { View } from "react-native" +import { BrigadeRequirementsProps } from "./type" +import { ItemBrigadeRequirement } from "../ItemBrigadeRequirement/ItemBrigadeRequirement" +import { IRequirement } from "@/entites/brigade/type/IRequirements" + +export const BrigadeRequirements: React.FC = ({ requirements }) => { + return ( + + { + requirements.map((data: IRequirement) => ) + } + + + ) +} diff --git a/src/entites/brigade/ui/requirement/BrigadeRequirements/type.ts b/src/entites/brigade/ui/requirement/BrigadeRequirements/type.ts new file mode 100644 index 0000000..078e22c --- /dev/null +++ b/src/entites/brigade/ui/requirement/BrigadeRequirements/type.ts @@ -0,0 +1,5 @@ +import { IRequirement } from "@/entites/brigade/type/IRequirements"; + +export interface BrigadeRequirementsProps { + requirements: IRequirement[] +} diff --git a/src/entites/brigade/ui/requirement/ItemBrigadeRequirement/ItemBrigadeRequirement.tsx b/src/entites/brigade/ui/requirement/ItemBrigadeRequirement/ItemBrigadeRequirement.tsx new file mode 100644 index 0000000..ba4d0ff --- /dev/null +++ b/src/entites/brigade/ui/requirement/ItemBrigadeRequirement/ItemBrigadeRequirement.tsx @@ -0,0 +1,17 @@ +import React from "react" +import { ItemBrigadeRequirementProps } from "./type" +import { Text, View } from "react-native" + +export const ItemBrigadeRequirement: React.FC = ({ requirement }) => { + return ( + + {requirement.exercise} + + minimum:{requirement.minimum} + + + maximum:{requirement.maximum} + + + ) +} diff --git a/src/entites/brigade/ui/requirement/ItemBrigadeRequirement/type.ts b/src/entites/brigade/ui/requirement/ItemBrigadeRequirement/type.ts new file mode 100644 index 0000000..af977de --- /dev/null +++ b/src/entites/brigade/ui/requirement/ItemBrigadeRequirement/type.ts @@ -0,0 +1,6 @@ +import { IRequirement } from "@/entites/brigade/type/IRequirements"; + +export interface ItemBrigadeRequirementProps { + requirement: IRequirement +} + diff --git a/src/features/auth/model/hooks/useAuth.ts b/src/features/auth/model/hooks/useAuth.ts index d0a5d64..2f56713 100644 --- a/src/features/auth/model/hooks/useAuth.ts +++ b/src/features/auth/model/hooks/useAuth.ts @@ -1,6 +1,6 @@ import { useRouter } from 'expo-router'; import { useAuthMutation } from "../../api/useMutation"; -import { IAuthVariables } from "../../type/IAuthVariables"; +import { IAuthVariables, IAuthVariablesHook } from "../../type/IAuthVariables"; import { useTokenStore } from '@/processes/tokenStorage/tokenStorage'; @@ -9,12 +9,13 @@ export const useAuth = () => { const authMutation = useAuthMutation() const router = useRouter(); const { createToken } = useTokenStore() - const handlerAuth = async ({ body, typePage }: IAuthVariables) => { + const handlerAuth = async ({ body, typePage, handlerZeroPage }: IAuthVariablesHook) => { try { const response = await authMutation.mutateAsync({ body, typePage }) createToken(response) router.navigate('/main') } catch (e) { + handlerZeroPage() console.error(e) } } diff --git a/src/features/auth/type/IAuthVariables.ts b/src/features/auth/type/IAuthVariables.ts index e30d95f..aa3e4c1 100644 --- a/src/features/auth/type/IAuthVariables.ts +++ b/src/features/auth/type/IAuthVariables.ts @@ -1,6 +1,19 @@ import { IloginBody, IRegistrationBody } from "@/shared/type/Auth"; +import { AuthProps } from "@/shared/type/AuthProps/type"; +import { ITypePage } from "@/shared/type/ITypePage/ITypePage"; -export type IAuthVariables = - | { typePage: "login"; body: IloginBody } - | { typePage: "registration"; body: IRegistrationBody }; +type IAuthBodyMap = { + login: IloginBody; + registration: IRegistrationBody; +}; + +export type IAuthVariables = { + typePage: T; + body: IAuthBodyMap[T]; +}; + +export type IAuthVariablesHook = + IAuthVariables & { + handlerZeroPage: () => void; + }; diff --git a/src/features/auth/ui/AuthForm/AuthForm.tsx b/src/features/auth/ui/AuthForm/AuthForm.tsx index 1ad775c..35445ae 100644 --- a/src/features/auth/ui/AuthForm/AuthForm.tsx +++ b/src/features/auth/ui/AuthForm/AuthForm.tsx @@ -10,53 +10,72 @@ import { useAuth } from "../../model/hooks/useAuth" import { ErrorField } from "@/shared/ui/ErrorField/ErrorField" import { useEffect, useState } from "react" import { BrigadeSelector } from "@/entites/brigade/ui/BrigadeSelector/BrigadeSelector" +import { AuthFormProps } from "./AuthFormProps" -export const AuthForm: React.FC = ({ typePage }) => { +export const AuthForm: React.FC = ({ typePage, setStateRegister, stateRegister }) => { const isLogin = typePage === 'login' const { handlerAuth, isError, error } = useAuth() - const [stateRegister, setStateRegister] = useState(false) type FormData = typeof isLogin extends true ? IloginBody : IRegistrationBody const { handleSubmit, control, - formState: { errors, isValid }, + formState: { errors }, setValue, } = useForm() const onSubmit = async (body: FormData) => { - - await handlerAuth({ body, typePage }); + await handlerAuth({ body, typePage, handlerZeroPage }); }; - const handlerSwitchPage = () => { - setStateRegister(!stateRegister) + const handlerZeroPage = () => { + setStateRegister(0) + } + const handlerNextPage = () => { + if (stateRegister != 2) setStateRegister(++stateRegister) } + const handlerPreviousPage = () => { + if (stateRegister != 0) setStateRegister(--stateRegister) + } + const authFormData = typePage == "login" ? LoginFormData : RegistrationFormData - console.log(error?.response?.data.message) return ( - {!stateRegister && + {stateRegister == 0 && authFormData.map((elem, index) => - ) } - {stateRegister && } + {stateRegister > 0 && } + - {typePage == "registration" && - - } + {typePage == "registration" && stateRegister == 0 && + + } + {typePage == "registration" && stateRegister > 0 && + + } {typePage != "registration" && - } + } ) diff --git a/src/features/auth/ui/AuthForm/AuthFormProps.ts b/src/features/auth/ui/AuthForm/AuthFormProps.ts new file mode 100644 index 0000000..aabaad9 --- /dev/null +++ b/src/features/auth/ui/AuthForm/AuthFormProps.ts @@ -0,0 +1,10 @@ +import { AuthProps } from "@/shared/type/AuthProps/type"; +import React from "react"; + + +export interface AuthFormProps extends AuthProps { + setStateRegister: React.Dispatch> + stateRegister: number + +} + diff --git a/src/features/auth/ui/AuthLink/AuthLink.tsx b/src/features/auth/ui/AuthLink/AuthLink.tsx index cdd31a5..70b49ec 100644 --- a/src/features/auth/ui/AuthLink/AuthLink.tsx +++ b/src/features/auth/ui/AuthLink/AuthLink.tsx @@ -1,67 +1,46 @@ -import { AuthProps } from "@/shared/type/AuthProps/type"; import { useRouter } from "expo-router"; -import { Text, StyleSheet, Pressable,View } from 'react-native'; +import { Text, StyleSheet, Pressable, View } from 'react-native'; import { useTheme } from 'react-native-paper'; import { loginLinkData, registrationLinkData } from "./data/authLink.data"; +import { AuthProps } from "@/shared/type/AuthProps/type"; + export const AuthLink: React.FC = ({ typePage }) => { const router = useRouter(); const theme = useTheme(); const handlePress = () => { - const url = typePage === "login" - ? registrationLinkData.link - : loginLinkData.link + const url = typePage == "login" ? registrationLinkData.link : loginLinkData.link router.navigate(url) }; - - return ( - + - - {typePage === 'login' ? `Forgot password? ` : `Already have an account? `} - - {typePage === 'login' ? registrationLinkData.text : loginLinkData.text} - + Already have an account? + + + {typePage === 'login' ? registrationLinkData.text : loginLinkData.text} + ) } const styles = StyleSheet.create({ - - container:{ - flexDirection:'row', - justifyContent:'center', - alignItems:'center', - marginTop:30 - }, - - text:{ - display:'flex', - flexDirection:'row', - alignItems:'center', - color: "white" - - }, link: { - color:'white', textDecorationLine: 'underline', fontWeight: '500', + paddingTop: 20, textAlign: 'center', - fontSize: 16, + fontSize: 16, }, - register:{ + register: { }, - login:{ + login: { } diff --git a/src/features/auth/ui/AuthLink/type.ts b/src/features/auth/ui/AuthLink/type.ts index f72a203..b4f0466 100644 --- a/src/features/auth/ui/AuthLink/type.ts +++ b/src/features/auth/ui/AuthLink/type.ts @@ -1,3 +1,4 @@ +import { ITypePage } from "@/shared/type/ITypePage/ITypePage"; import { ExternalPathString } from "expo-router"; export interface IAuthLink { diff --git a/src/shared/type/AuthProps/type.ts b/src/shared/type/AuthProps/type.ts index 4a6111d..72a2b91 100644 --- a/src/shared/type/AuthProps/type.ts +++ b/src/shared/type/AuthProps/type.ts @@ -1,5 +1,7 @@ +import React from "react"; +import { ITypePage } from "../ITypePage/ITypePage"; export interface AuthProps { - typePage: "login" | "registration"; + typePage: ITypePage } diff --git a/src/shared/type/ITypePage/ITypePage.ts b/src/shared/type/ITypePage/ITypePage.ts new file mode 100644 index 0000000..6b40c4e --- /dev/null +++ b/src/shared/type/ITypePage/ITypePage.ts @@ -0,0 +1,2 @@ + +export type ITypePage = "login" | "registration"; diff --git a/src/shared/ui/InputController/type.ts b/src/shared/ui/InputController/type.ts index 37dd99e..0dd8a39 100644 --- a/src/shared/ui/InputController/type.ts +++ b/src/shared/ui/InputController/type.ts @@ -1,8 +1,10 @@ +import { ITypePage } from "@/shared/type/ITypePage/ITypePage"; import { InputConfig } from "../../type/InputConfig/type"; export interface InputControllerProps { control: any; errors: any; + typePage: ITypePage input: InputConfig } diff --git a/src/widgets/auth/auth.tsx b/src/widgets/auth/auth.tsx index 2462450..197c11e 100644 --- a/src/widgets/auth/auth.tsx +++ b/src/widgets/auth/auth.tsx @@ -1,14 +1,24 @@ -import React from "react"; +import React, { useState } from "react"; import { AuthForm, AuthLink } from "@/features/auth" import { AuthTitle } from "@/features/auth/ui/AuthTitle/AuthTitle" import { AuthProps } from "@/shared/type/AuthProps/type" +<<<<<<< HEAD import { View, Text, StyleSheet,ImageBackground,} from "react-native" +======= +import { View, Text, StyleSheet } from "react-native" +>>>>>>> main +function AuthText(props: { text: string }) { + return {props.text}; +} export const Auth: React.FC = ({ typePage }) => { + const [stateRegister, setStateRegister] = useState(0) + return ( +<<<<<<< HEAD = ({ typePage }) => { flex: 1, } }) +======= + + {!stateRegister && } + + {!stateRegister && } + + + + ) +} + +const styles = StyleSheet.create({ + subtitle: { + fontSize: 32, + fontWeight: 700, + paddingLeft: 41, + marginBottom: 26, + + + }, + back: { + backgroundColor: "rgb(216, 216, 216)", + height: 917, + } +}) +>>>>>>> main