Skip to content

Commit

Permalink
Merge pull request #118 from LamArt/feature/SCHOOL-796
Browse files Browse the repository at this point in the history
two types of students are published
  • Loading branch information
zavarin-michael authored Mar 18, 2024
2 parents 05b9f0e + 01de40e commit e2f6123
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 77 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect, useState } from 'react'
import { Col, Row, Typography } from 'antd'
import { Col, Row, Spin, Typography } from 'antd'
import Image from 'next/image'

import { getUuidFromUrl } from '@domains/common/utils/getUuidFromUrl'
Expand All @@ -22,6 +22,7 @@ const CurrentEmployee = () => {
const {
data: employee,
error: employeeError,
isLoading,
} = useGetEmployeeQuery({
employee_id: uuid[0],
})
Expand All @@ -35,7 +36,9 @@ const CurrentEmployee = () => {
if (isDeleteFinished.isSuccess) return null
if (uuid.length === 0) router.push('/404')

return (
return isLoading ? (
<Spin />
) : (
<>
<Col className={styles.headersBlock}>
<Row className={styles.baseRowContainer}>
Expand Down
1 change: 1 addition & 0 deletions apps/schools/domains/organization/redux/organizationApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ export const {
useExportStudentsQuery,
useGetAllTeachersQuery,
useGetAllQueriesOfOrganizationQuery,
useLazyGetAllStudentInvitationsQuery,
useGetAllStudentInvitationsQuery,
useGetAllCirclesQuery,
useGetAllJoinCircleQueriesQuery,
Expand Down
206 changes: 131 additions & 75 deletions apps/schools/domains/student/components/currentStudent/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { useEffect, useState } from 'react'
import { Col, Row, Typography } from 'antd'
import { Col, Row, Spin, Tooltip, Typography } from 'antd'
import Image from 'next/image'

import { useGetStudentQuery } from '@domains/organization/redux/organizationApi'
import { useGetStudentQuery, useLazyGetAllStudentInvitationsQuery } from '@domains/organization/redux/organizationApi'
import { getUuidFromUrl } from '@domains/common/utils/getUuidFromUrl'

import EmptyWrapper from '@domains/common/components/containers/EmptyWrapper'
Expand All @@ -15,101 +15,157 @@ import { Field } from '@domains/common/components/field'
import { useDeleteStudentMutation } from '@domains/student/redux/studentApi'
import { ActionBar } from '@domains/common/components/stickyBlock/actionBar'
import DeleteModal from '@domains/common/components/deleteModal'
import { GetStudent } from '@domains/common/redux/serializers'
import { useOrganization } from '@domains/organization/providers/organizationProvider'
import parentAcceptedPhone from '@public/icons/parentAcceptedMobile.svg'
import parentDeclinedPhone from '@public/icons/parentDeclinedMobile.svg'

const CurrentStudent = () => {
const [isModalVisible, setIsModalVisible] = useState(false)
const [mutation, isDeleteFinished] = useDeleteStudentMutation()
const { organizationId } = useOrganization()
const uuid = getUuidFromUrl()

const { data: student, error: studentError, isLoading } = useGetStudentQuery({ student_id: uuid[0] })
const [mutation, isDeleteFinished] = useDeleteStudentMutation()

const [student, setStudent] = useState<GetStudent | undefined>(undefined)
const { data: studentInfo, error: studentError, isLoading } = useGetStudentQuery({ student_id: uuid[0] })
const [trigger, studentInfoAdditional] = useLazyGetAllStudentInvitationsQuery()
const isVerifiedStudent = studentInfo?.student.circle && studentInfo?.student.circle

useEffect(() => {
if (studentError && (studentError as ErrorType).status == 404) {
if (studentError && ((studentError as ErrorType).status == 404 || (studentError as ErrorType).status == 403)) {
router.push('/student')
}
}, [studentError])

useEffect(() => {
if (isVerifiedStudent) {
setStudent(studentInfo.student)
} else {
trigger({ student__id: uuid[0], circle__organization__id: organizationId })
}
}, [studentInfo])

useEffect(() => {
const info = studentInfoAdditional.data?.results[0]
if (info)
setStudent({
id: uuid[0],
name: info.body.name,
student_profile: {
parent_phones: info.recipient?.parent_phones,
name: '',
phone: info.additional.phone,
photo: {},
},
circle: {
name: info.sender.name,
},
})
}, [studentInfoAdditional])

if (isDeleteFinished.isSuccess) return null
if (uuid.length === 0) router.push('/404')

return (
<EmptyWrapper
titleText={'Упс, зайдите позже!'}
descriptionText={
'Ваше приглашение в кружок пока рассматривается. ' +
'Уже скоро здесь появится информация об обучающемся!'
}
titleText={'Упс, произошла ошибка!'}
descriptionText={'Попробуйте перезагрузить страницу. ' + 'Мы уже работаем над исправлением ошибки.'}
pageTitle={'Обучающийся'}
data={student?.student.circle ?? student?.student.student_profile}
isLoading={isLoading}
data={student}
isLoading={isLoading || studentInfoAdditional.isLoading}
searchTrigger={false}
>
<Row className={styles.headersBlock}>
<Col lg={14} md={24} xs={24} sm={24} className={styles.infoBlock}>
<Row className={styles.baseRowContainer}>
<Col lg={4} className={styles.image}>
<Image src={duckEmptyPage} alt={'Duck with a magnifying glass'} width={190} />
</Col>
<Col className={styles.infoContainer} lg={24}>
<Typography.Title className={styles.title} level={1}>
{student?.student.name ? student?.student.name : 'Имя не определено'}
</Typography.Title>
<Field
fieldName={'Телефон ученика:'}
fieldValue={student?.student.student_profile?.phone}
/>
<Field fieldName={'Кружок:'} fieldValue={student?.student.circle?.name} />
<div className={styles.stickyBlock}>
<ActionBar
actions={[
<Button
key={'edit'}
className={styles.changeButton}
onClick={() => router.push(`/student/${uuid[0]}/change`)}
>
Редактировать профиль
</Button>,
<Button
antdType={'ghost'}
className={styles.deleteButton}
key='submit'
danger
onClick={() => setIsModalVisible(true)}
{isLoading || studentInfoAdditional.isLoading ? (
<Spin />
) : (
<>
<Row className={styles.headersBlock}>
<Col lg={14} md={24} xs={24} sm={24} className={styles.infoBlock}>
<Row className={styles.baseRowContainer}>
<Col lg={4} className={styles.image}>
<Image src={duckEmptyPage} alt={'Duck with a magnifying glass'} width={190} />
</Col>
<Col className={styles.infoContainer} lg={24}>
<Row className={styles.title}>
<Typography.Title level={1}>
{student?.name ? student?.name : 'Имя не определено'}
</Typography.Title>
<Tooltip
title={
isVerifiedStudent
? 'Родитель принял вашу заявку'
: 'Родитель пока не принял вашу заявку'
}
>
Удалить
</Button>,
]}
/>
</div>
<Image
src={isVerifiedStudent ? parentAcceptedPhone : parentDeclinedPhone}
alt={'Parent phone'}
width={50}
/>
</Tooltip>
</Row>
<Field
fieldName={'Телефон ученика:'}
fieldValue={student?.student_profile?.phone}
/>
<Field fieldName={'Кружок:'} fieldValue={student?.circle?.name} />
<div className={styles.stickyBlock}>
<ActionBar
actions={[
<Button
key={'edit'}
className={styles.changeButton}
onClick={() => router.push(`/student/${uuid[0]}/change`)}
>
Редактировать профиль
</Button>,
<Button
antdType={'ghost'}
className={styles.deleteButton}
key='submit'
danger
onClick={() => setIsModalVisible(true)}
>
Удалить
</Button>,
]}
/>
</div>
</Col>
</Row>
</Col>
{student?.circle && (
<Col lg={10} md={24} xs={24} sm={24} className={styles.card}>
<div className={styles.text}>
<Typography.Title level={2}>Семья</Typography.Title>
<Field
fieldName={'Номер для связи:'}
fieldValue={student?.student_profile?.phone}
defaultValue={'Не определено'}
type='left'
/>
<Field
fieldName={'Телефон родителя:'}
fieldValue={student?.student_profile?.parent_phones?.split(',')[0]}
type='left'
/>
<Field fieldName={'E-mail родителя:'} type='left' />
</div>
</Col>
)}
</Row>
</Col>
<Col lg={10} md={24} xs={24} sm={24} className={styles.card}>
<div className={styles.text}>
<Typography.Title level={2}>Семья</Typography.Title>
<Field
fieldName={'Номер для связи:'}
fieldValue={student?.student.student_profile?.phone}
type='left'
/>
<Field
fieldName={'Телефон родителя:'}
fieldValue={student?.student.student_profile?.parent_phones?.split(',')[0]}
type='left'
/>
<Field fieldName={'E-mail родителя:'} defaultValue={'Не определено'} type='left' />
</div>
</Col>
</Row>
<DeleteModal
isModalVisible={isModalVisible}
mutation={mutation}
setIsModalVisible={setIsModalVisible}
titleText={'Удалить обучающегося?'}
buttonText={'Удалить обучающегося'}
urlAfterDelete={'/student'}
dataField={'student_id'}
/>
<DeleteModal
isModalVisible={isModalVisible}
mutation={mutation}
setIsModalVisible={setIsModalVisible}
titleText={'Удалить обучающегося?'}
buttonText={'Удалить обучающегося'}
urlAfterDelete={'/student'}
dataField={'student_id'}
/>
</>
)}
</EmptyWrapper>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
}

.title {
gap: 20px;
margin-bottom: 50px;
}

Expand Down
1 change: 1 addition & 0 deletions apps/schools/public/icons/parentAcceptedMobile.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions apps/schools/public/icons/parentDeclinedMobile.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e2f6123

Please sign in to comment.