Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

circle create page with validators and select features #79

Merged
merged 3 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { useGetAllCirclesQuery } from '@domains/organization/redux/organizationA
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/student/components/studentList/utils'
import { getVarsForAddressColumn } from '@domains/common/utils/geo'

export function CircleList() {
const [searchRequestText, setSearchRequestText] = useState('')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const CIRCLE_NAME = 'circle_name'
export const CIRCLE_ADDRESS = 'circle_address'
export const ADDRESS_ROOM = 'address_room'
30 changes: 30 additions & 0 deletions apps/schools/domains/circle/components/createCircleForm/hooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { useMemo } from 'react'
import { PleaseInputAddressMsg, PleaseInputCircleNameMsg } from '@domains/user/components/auth/constants/message'
import { ValidatorsMap } from '@domains/common/redux/interfaces'
import { getGreaterValidator } from '@domains/common/utils/validators'

export const useCreateCircleFormValidators = () => {
return useMemo<ValidatorsMap>(() => {
return {
name: [
{
required: true,
message: PleaseInputCircleNameMsg,
whitespace: true,
type: 'string',
},
getGreaterValidator(200),
],
address: [
{
required: true,
message: PleaseInputAddressMsg,
whitespace: true,
type: 'string',
},
getGreaterValidator(200),
],
room: [getGreaterValidator(55)],
}
}, [this])
}
143 changes: 143 additions & 0 deletions apps/schools/domains/circle/components/createCircleForm/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import { Form, Typography, Input as AntdInput, Row, Spin } from 'antd'
import React, { 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 } from '@ant-design/icons'
import { Select } from '@domains/common/components/select'
import { handleSubmitForm } from '../../handlers/circle'
import { useCreateCircleMutation } from '../../redux/circleApi'
import { getVarsForAddressColumn } from '@domains/common/utils/geo'

export const CreateCircleForm = () => {
const validators = useCreateCircleFormValidators()
const { organization, organizationId } = useOrganization()
const [form] = Form.useForm()
const [isFormValid, setIsFormValid] = useState(false)
const [mutation] = useCreateCircleMutation()
const circlesData = useGetAllCirclesQuery({
organization_id: organization.id,
})
const circlesAddresses = Array.from(
new Set(circlesData?.data?.results.map((x) => getVarsForAddressColumn(x.address)[0])),
)

const validationCheck = () => {
setIsFormValid(isValidFormCheck(form, [CIRCLE_NAME]))
}

return (
<Row className={styles.mainRow}>
<div className={styles.formContainer}>
<Form
form={form}
className={styles.table}
colon={false}
requiredMark={false}
onValuesChange={validationCheck}
onFinish={() => {
handleSubmitForm(organizationId, form, mutation).then((isSucceed) => {
if (isSucceed) window.location.href = '/circle'
})
}}
layout='vertical'
>
<Typography.Title level={1}>Добавление кружка</Typography.Title>
<WithTooltip tooltipText={'Здесь будет текст тултипа'} margin={TOOLTIP_MARGIN}>
zavarin-michael marked this conversation as resolved.
Show resolved Hide resolved
<Form.Item
required={true}
label={
<span>
<span className={styles.requiredMark}>*</span> Название
</span>
}
name={CIRCLE_NAME}
className={styles.label}
rules={validators.name}
>
<Input required={true} placeholder='Введите название кружка' />
</Form.Item>
</WithTooltip>

<Row className={styles.complexInputContainer}>
{!circlesData.isLoading ? (
<>
<AntdInput.Group compact className={styles.complexInput}>
<Form.Item
required={true}
label={
<span>
<span className={styles.requiredMark}>*</span> Адрес
</span>
}
name={CIRCLE_ADDRESS}
initialValue={circlesAddresses[0]}
className={classnames(styles.label, styles.address)}
rules={validators.address}
>
<Select
placeholder='Выберите адрес кружка'
customType={'selectInput'}
className={styles.select}
loading={circlesData.isLoading}
options={circlesAddresses?.map((x: string | undefined) => {
return {
value: x,
label: x,
}
})}
/>
</Form.Item>

<Form.Item
label={'Помещение'}
name={ADDRESS_ROOM}
className={classnames(styles.label, styles.room)}
initialValue={''}
rules={validators.room}
>
<Input className={styles.input} placeholder='Помещение и номер' />
</Form.Item>
</AntdInput.Group>

<Button className={styles.mapButton} antdType={'text'} icon={<AimOutlined />}>
Выбрать на карте
</Button>
</>
) : (
<Spin></Spin>
)}
</Row>

<Form.Item name='button'>
<Button
disabled={!isFormValid}
key='submit'
type='schoolDefault'
htmlType='submit'
block
data-cy='resetcomplete-button'
className={styles.button}
>
Добавить кружок
</Button>
</Form.Item>
</Form>
</div>
<div className={styles.mobileApp}>
<Typography.Title level={3}>Приложение родителей</Typography.Title>
<Typography.Title level={3} className={styles.text}>
Родители смогут увидеть ваш кружок с помощью карты и узнать информацию о нём!
</Typography.Title>
</div>
</Row>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
@import '../../../../common/components/styles/abstracts/colors';

.mainRow {
height: 100px;
justify-content: space-between;

.formContainer {
width: 700px;

.table {
max-width: 550px;

.requiredMark {
color: $color-required-mark;
}

.label {
font-family: 'Roboto', sans-serif;
font-size: 14px;
font-style: normal;
font-weight: 400;
line-height: 22px;
}

.complexInputContainer {
width: 125%;

.complexInput {
width: 76%;

.address {
width: 65%;
border-radius: 0;

.input {
border-top-right-radius: 0;
border-bottom-right-radius: 0;
}
}

.room {
width: 35%;

.input {
border-top-left-radius: 0;
border-bottom-left-radius: 0;
}
}
}

.mapButton {
width: 24%;
margin-top: 38px;
color: $main-blue-color;
padding-left: 1%;
}
}


.button {
width: 30%;
text-align: center;
font-family: 'Roboto', sans-serif;
font-size: 16px;
font-style: normal;
font-weight: 400;
line-height: 24px;
}
}
}

.mobileApp {
padding-left: 60px;
padding-right: 60px;
padding-top: 30px;
margin-top: 20px;
height: 814px;
width: 505px;
border-radius: 12px;
background: linear-gradient(180deg, rgba(24, 144, 255, 0.3) 0%, rgba(245, 245, 245, 0.00) 100%);

.text{
font-size: 24px;
font-style: normal;
font-weight: 600;
line-height: 130%;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const TOOLTIP_MARGIN = '47px'
27 changes: 27 additions & 0 deletions apps/schools/domains/circle/handlers/circle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { FormInstance, message } from 'antd'
import { LoadingRequestMsg, SuccessCreateCircleMsg } from '@domains/user/components/auth/constants/message'
import { removeEmpty } from '@domains/common/utils/form'
import { CIRCLE_NAME, CIRCLE_ADDRESS, ADDRESS_ROOM } from '../components/createCircleForm/constants'
import { withLoadingMessage } from '@domains/common/utils/loading'
import { ADDRESS_SEPARATOR } from '@domains/common/utils/geo'

export async function handleSubmitForm(organizationId: string, formComponent: FormInstance, mutation: any) {
const response = await withLoadingMessage(
LoadingRequestMsg,
mutation,
removeEmpty({
organization: organizationId,
name: formComponent.getFieldValue(CIRCLE_NAME),
address: `${formComponent.getFieldValue(CIRCLE_ADDRESS)}${ADDRESS_SEPARATOR}${formComponent.getFieldValue(
ADDRESS_ROOM,
)}`,
}),
)

if ('data' in response) {
message.success(SuccessCreateCircleMsg)
return true
}

return false
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
}

.logoText {
color: var(--unnamed, #2698FF);
font-family: "Roboto";
color: $main-blue-color;
font-family: "Roboto", sans-serif;
font-size: 20px;
font-style: normal;
font-weight: 700;
Expand Down
Loading
Loading