Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…-frontend into fix/SCHOOL-840/saving-settings-when-page-reloaded
  • Loading branch information
levil664 committed Jul 17, 2024
2 parents 9eea2e8 + 41ad5fe commit df831a5
Show file tree
Hide file tree
Showing 21 changed files with 330 additions and 265 deletions.
32 changes: 14 additions & 18 deletions apps/schools/domains/circle/components/changeCircleForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import { Button } from '@domains/common/components/button'
import { useChangeCircleFormValidators } from './hooks'
import { useGetAllCirclesQuery } from '@domains/organization/redux/organizationApi'
import { useOrganization } from '@domains/organization/providers/organizationProvider'
import { WithTooltip } from '@domains/common/components/tooltip/withTooltip'
import { TOOLTIP_MARGIN } from './styles/styles'
import { isValidFormCheck } from '@domains/common/utils/form'
import { CIRCLE_NAME, CIRCLE_ADDRESS, ADDRESS_ROOM } from './constants'
import classnames from 'classnames'
Expand Down Expand Up @@ -80,22 +78,20 @@ export const ChangeCircleForm = () => {
layout='vertical'
>
<Typography.Title level={1}>Редактирование кружка</Typography.Title>
<WithTooltip tooltipText={'Здесь будет текст тултипа'} margin={TOOLTIP_MARGIN}>
<Form.Item
required={true}
label={
<span>
<span className={styles.requiredMark}>*</span> Название
</span>
}
name={CIRCLE_NAME}
className={styles.label}
rules={validators.name}
initialValue={initialValues[CIRCLE_NAME]}
>
<Input required={true} placeholder='Введите название кружка' />
</Form.Item>
</WithTooltip>
<Form.Item
required={true}
label={
<span>
<span className={styles.requiredMark}>*</span> Название
</span>
}
name={CIRCLE_NAME}
className={styles.label}
rules={validators.name}
initialValue={initialValues[CIRCLE_NAME]}
>
<Input required={true} placeholder='Введите название кружка' />
</Form.Item>

<Row className={styles.complexInputContainer}>
{!circlesData.isLoading ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
font-style: normal;
font-weight: 400;
line-height: 22px;
width: 95%;

:global {
.ant-select-selector {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { RowType, TableType } from './interfaces'
import { searchStudentsColumns } from './constants'
import { useGetAllCirclesQuery } from '@domains/organization/redux/organizationApi'
import EmptyWrapper from '@domains/common/components/containers/EmptyWrapper'
import { mapReturnedData } from '@domains/common/redux/utils'
import { HighlightText } from '@domains/common/components/table/forming'
import { getVarsForAddressColumn } from '@domains/common/utils/geo'
import { AppRoutes, RoutePath } from '@domains/common/constants/routerEnums'
Expand Down Expand Up @@ -97,6 +96,7 @@ export function CircleList() {
customWidths={[60, 25, 15]}
searchRequestText={searchRequestText}
setSearchRequestText={setSearchRequestText}
rowClassName={styles.tableRowPointer}
/>
</EmptyWrapper>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,8 @@
font-style: normal;
font-weight: 400;
line-height: 22px;
}
}

.tableRowPointer:hover {
cursor: pointer;
}
38 changes: 5 additions & 33 deletions apps/schools/domains/circle/components/createCircleForm/index.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import { Form, Typography, Input as AntdInput, Row, Spin, Tooltip } from 'antd'
import { Form, Typography, Input as AntdInput, Row, Spin } from 'antd'
import React, { useEffect, useState } from 'react'
import { Input } from '@domains/common/components/input'
import styles from './styles/styles.module.scss'
import { Button } from '@domains/common/components/button'
import { useCreateCircleFormValidators } from './hooks'
import { useGetAllCirclesQuery } from '@domains/organization/redux/organizationApi'
import { useOrganization } from '@domains/organization/providers/organizationProvider'
import { WithTooltip } from '@domains/common/components/tooltip/withTooltip'
import { TOOLTIP_MARGIN } from './styles/styles'
import { isValidFormCheck } from '@domains/common/utils/form'
import { CIRCLE_NAME, CIRCLE_ADDRESS, ADDRESS_ROOM } from './constants'
import classnames from 'classnames'
import { AimOutlined, QuestionCircleFilled } from '@ant-design/icons'
import { AimOutlined } from '@ant-design/icons'
import { Select } from '@domains/common/components/select'
import { useCreateCircleMutation } from '../../redux/circleApi'
import { getVarsForAddressColumn } from '@domains/common/utils/geo'
Expand All @@ -21,14 +19,6 @@ import { mapSteps } from '@domains/circle/interfaces/mapStepsType'
import { FormMapSteps } from '@domains/circle/constants/Enums'
import Image from 'next/image'
import android from '@public/image/Android 11.png'
import {
DEFAULT_ICON_SIZE,
DEFAULT_MARGIN,
DEFAULT_OVERLAY_INNER_COLOR,
DEFAULT_OVERLAY_INNER_STYLE,
ICON_SIZES,
} from '@domains/common/components/tooltip/styles/styles'
import { BackPage } from '@domains/common/components/backPage'

export const CreateCircleForm = () => {
const validators = useCreateCircleFormValidators()
Expand Down Expand Up @@ -93,28 +83,10 @@ export const CreateCircleForm = () => {
>
<Input
required={true}
inputContainerClass={styles.inputWithTooltipContainer}
className={styles.inputWithTooltip}
inputContainerClass={styles.inputContainer}
className={styles.input}
placeholder='Введите название кружка'
>
<div className={styles.tooltipContainer}>
<Tooltip
placement='right'
title={'Здесь будет текст тултипа'}
color={DEFAULT_OVERLAY_INNER_COLOR}
style={{ height: 'auto' }}
overlayInnerStyle={DEFAULT_OVERLAY_INNER_STYLE}
>
<QuestionCircleFilled
style={{
top: `${TOOLTIP_MARGIN}`,
marginBottom: '10px',
fontSize: ICON_SIZES[DEFAULT_ICON_SIZE],
}}
/>
</Tooltip>
</div>
</Input>
/>
</Form.Item>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@
width: 3%;
}

.inputWithTooltipContainer {
.inputContainer {
display: flex;
flex-direction: row;
justify-content: unset;
}

.inputWithTooltip {
.input {
width: 70%;
margin-right: 5px;
display: flex;
Expand Down
43 changes: 43 additions & 0 deletions apps/schools/domains/common/handlers/paginationChange.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
export const handlePaginationChange = (
setPaginationParams: (params: { page: number; pageSize: number }) => void,
setQueryPaginationParams: (params: { [key: string]: { page: number; pageSize: number } }) => void,
counts: { [key: string]: number | undefined },
newPage: number,
newPageSize: number,
defaultPaginationTablePage: number,
defaultPaginationTablePageSize: number,
scrollToTop: () => void,
) => {
setPaginationParams({
page: newPage,
pageSize: newPageSize,
})

const newQueryParams: { [key: string]: { page: number; pageSize: number } } = {}

let currentPage = newPage
let currentOffset = 0

Object.keys(counts).forEach((key, index) => {
const count = counts[key] ?? 0
const maxPages = Math.ceil(count / newPageSize)

if (currentPage <= maxPages) {
newQueryParams[key] = {
page: currentPage,
pageSize: newPageSize,
}
} else {
currentPage -= maxPages
newQueryParams[key] = {
page: defaultPaginationTablePage,
pageSize: defaultPaginationTablePageSize,
}
}

currentOffset += count
})

setQueryPaginationParams(newQueryParams)
scrollToTop()
}
4 changes: 2 additions & 2 deletions apps/schools/domains/common/redux/serializers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ interface GetStudentProfile {
id?: string
name: string
age?: number
phone?: string
phone: string
photo: GetPhoto
parent_names?: string
parent_phones?: string
parent_phones: string
}

export interface GetAnalytics {
Expand Down
5 changes: 5 additions & 0 deletions apps/schools/domains/common/utils/getTotalPages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const getTotalPages = (counts: { [key: string]: { count: number | undefined } }, pageSize: number) => {
return Object.keys(counts).reduce((total, key) => {
return total + Math.ceil((counts[key].count ?? 0) / pageSize) * pageSize
}, 0)
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import { useCreateEmployeeFormValidators } from './hooks'
import { useInviteEmployeeMutation } from '@domains/organization/redux/organizationApi'
import { useOrganization } from '@domains/organization/providers/organizationProvider'
import { handleSubmitForm } from '@domains/employee/handlers/employeeCreate'
import router, { useRouter } from 'next/router'
import { WithTooltip } from '@domains/common/components/tooltip/withTooltip'
import { TOOLTIP_MARGIN } from '@domains/employee/components/createEmployeeForm/styles/styles'
import { useRouter } from 'next/router'
import { isValidFormCheck } from '@domains/common/utils/form'
import {
EMPLOYEE_EMAIL,
Expand Down Expand Up @@ -45,55 +43,42 @@ export const CreateEmployeeForm = () => {
}}
layout='vertical'
>
<Typography.Title level={1}>Добавление Сотрудника</Typography.Title>
<WithTooltip tooltipText={'Здесь будет текст тултипа'} margin={TOOLTIP_MARGIN}>
<Form.Item
required={true}
label={
<span>
<span className={styles.requiredMark}>*</span> Телефон сотрудника
</span>
}
name={EMPLOYEE_PHONE}
className={styles.label}
rules={validators.phone}
>
<Input required={true} customType='inputPhone' placeholder='Введите телефон сотрудника' />
</Form.Item>
</WithTooltip>
<Typography.Title level={1}>Добавление сотрудника</Typography.Title>
<Form.Item
required={true}
label={
<span>
<span className={styles.requiredMark}>*</span> Телефон сотрудника
</span>
}
name={EMPLOYEE_PHONE}
className={styles.label}
rules={validators.phone}
>
<Input required={true} customType='inputPhone' placeholder='Введите телефон сотрудника' />
</Form.Item>

<WithTooltip tooltipText={'Здесь будет текст тултипа'} margin={TOOLTIP_MARGIN}>
<Form.Item
required
label={
<span>
<span className={styles.requiredMark}>*</span> Ф. И. О. сотрудника
</span>
}
name={EMPLOYEE_NAME}
className={styles.label}
rules={validators.name}
>
<Input placeholder='Введите Ф. И. О. сотрудника' />
</Form.Item>
</WithTooltip>
<Form.Item
required
label={
<span>
<span className={styles.requiredMark}>*</span> Ф. И. О. сотрудника
</span>
}
name={EMPLOYEE_NAME}
className={styles.label}
rules={validators.name}
>
<Input placeholder='Введите Ф. И. О. сотрудника' />
</Form.Item>

<WithTooltip tooltipText={'Здесь будет текст тултипа'} margin={TOOLTIP_MARGIN}>
<Form.Item
label='Email сотрудника'
name={EMPLOYEE_EMAIL}
className={styles.label}
rules={validators.email}
>
<Input type='email' placeholder='Введите email сотрудника' />
</Form.Item>
</WithTooltip>
<Form.Item label='Email сотрудника' name={EMPLOYEE_EMAIL} className={styles.label} rules={validators.email}>
<Input type='email' placeholder='Введите email сотрудника' />
</Form.Item>

<WithTooltip tooltipText={'Здесь будет текст тултипа'} margin={TOOLTIP_MARGIN}>
<Form.Item label='Должность сотрудника' name={EMPLOYEE_POSITION} className={styles.label}>
<Input placeholder='Введите должность сотрудника' />
</Form.Item>
</WithTooltip>
<Form.Item label='Должность сотрудника' name={EMPLOYEE_POSITION} className={styles.label}>
<Input placeholder='Введите должность сотрудника' />
</Form.Item>

<Form.Item name='button'>
<Button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
font-style: normal;
font-weight: 400;
line-height: 22px;
width: 90%;
}

.button {
Expand Down
23 changes: 23 additions & 0 deletions apps/schools/domains/organization/redux/organizationApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { mapReturnedData } from '@domains/common/redux/utils'
import { TableType as TableTypeCircle } from '@domains/circle/components/circleList/interfaces'
import { TableType as TableTypeTickets } from '@domains/ticket/components/ticketList/interfaces'
import { TableType as TableTypeQuery } from '@domains/query/components/queryList/interfaces'
import { TableType as TableTypeStudent } from '@domains/student/components/studentList/interfaces'

const organizationApi = commonApi.injectEndpoints({
endpoints: (build) => ({
Expand Down Expand Up @@ -70,6 +71,17 @@ const organizationApi = commonApi.injectEndpoints({
method: 'GET',
params: params,
}),
transformResponse: (response: ReturnedData<GetStudent[]>) => {
return mapReturnedData(response, (query) => {
const transformedQuery = structuredClone(query) as unknown as TableTypeStudent
transformedQuery.id = query.id
transformedQuery.student_name = query.name
transformedQuery.student_phone = query.student_profile.phone
transformedQuery.parent_phone = query.student_profile.parent_phones?.replaceAll(',', '\n')
transformedQuery.circle_name = query.circle.name
return transformedQuery
})!
},
providesTags: (result) => providesList(result?.results, 'Student'),
}),
getAllCircles: build.query<ReturnedData<TableTypeCircle[]>, GetOrganizationCircleListData>({
Expand Down Expand Up @@ -168,6 +180,17 @@ const organizationApi = commonApi.injectEndpoints({
method: 'GET',
params: params,
}),
transformResponse: (response: ReturnedData<GetCircleInviteStudent[]>) => {
return mapReturnedData(response, (query) => {
const transformedQuery = structuredClone(query) as unknown as TableTypeStudent
transformedQuery.id = query.body.id
transformedQuery.student_name = query.body.name
transformedQuery.student_phone = query.additional.phone
transformedQuery.parent_phone = query.recipient.parent_phones.replaceAll(',', '\n')
transformedQuery.circle_name = query.sender.name
return transformedQuery
})!
},
providesTags: (result) => providesList(result?.results, 'Student'),
}),
getAllJoinCircleQueries: build.query<ReturnedData<GetStudentJoinCircle[]>, AllStudentJoinCircleQueriesData>({
Expand Down
Loading

0 comments on commit df831a5

Please sign in to comment.