generated from 8iq/nodejs-hackathon-boilerplate-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change circle page with some utils improvements
- Loading branch information
1 parent
e662c3c
commit 1f21f1c
Showing
14 changed files
with
316 additions
and
18 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
apps/schools/domains/circle/components/changeCircleForm/constants.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const CIRCLE_NAME: string = 'circle_name' | ||
export const CIRCLE_ADDRESS: string = 'circle_address' | ||
export const ADDRESS_ROOM: string = 'address_room' |
30 changes: 30 additions & 0 deletions
30
apps/schools/domains/circle/components/changeCircleForm/hooks.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 useChangeCircleFormValidators = () => { | ||
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]) | ||
} |
155 changes: 155 additions & 0 deletions
155
apps/schools/domains/circle/components/changeCircleForm/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
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 { 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' | ||
import { AimOutlined } from '@ant-design/icons' | ||
import { Select } from '@domains/common/components/select' | ||
import { handleSubmitForm } from '../../handlers/circle' | ||
import { useChangeCircleMutation, useGetCircleQuery } from '../../redux/circleApi' | ||
import { getVarsForAddressColumn } from '@domains/common/utils/geo' | ||
import { getUuidFromUrl } from '@domains/common/utils/getUuidFromUrl' | ||
|
||
export const ChangeCircleForm = () => { | ||
const validators = useChangeCircleFormValidators() | ||
const { organizationId } = useOrganization() | ||
const [form] = Form.useForm() | ||
const [isFormValid, setIsFormValid] = useState(false) | ||
const [mutation] = useChangeCircleMutation() | ||
|
||
const circleId = getUuidFromUrl()[0] | ||
|
||
const circleData = useGetCircleQuery({ | ||
circle_id: circleId, | ||
}) | ||
const currentCircle = circleData?.data?.circle | ||
|
||
const circlesData = useGetAllCirclesQuery({ | ||
organization_id: organizationId, | ||
}) | ||
const circlesAddresses = Array.from( | ||
new Set(circlesData?.data?.results.map((x) => getVarsForAddressColumn(x.address)[0])), | ||
) | ||
|
||
const initialValues = { | ||
[CIRCLE_NAME]: currentCircle?.name, | ||
[CIRCLE_ADDRESS]: getVarsForAddressColumn(currentCircle?.address ?? '')[0], | ||
[ADDRESS_ROOM]: getVarsForAddressColumn(currentCircle?.address ?? '')[1], | ||
} | ||
|
||
const validationCheck = () => { | ||
setIsFormValid(isValidFormCheck(form, [], initialValues)) | ||
} | ||
|
||
return !circleData.isLoading ? ( | ||
<Row className={styles.mainRow}> | ||
<div className={styles.formContainer}> | ||
<Form | ||
form={form} | ||
className={styles.table} | ||
colon={false} | ||
requiredMark={false} | ||
onValuesChange={validationCheck} | ||
onFinish={() => { | ||
handleSubmitForm(circleId, form, mutation).then((isSucceed) => { | ||
if (isSucceed) window.location.href = `/circle/${circleId}` | ||
}) | ||
}} | ||
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> | ||
|
||
<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={initialValues[CIRCLE_ADDRESS]} | ||
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={initialValues[ADDRESS_ROOM]} | ||
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> | ||
</Row> | ||
) : ( | ||
<Spin></Spin> | ||
) | ||
} |
71 changes: 71 additions & 0 deletions
71
apps/schools/domains/circle/components/changeCircleForm/styles/styles.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
@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: 40%; | ||
text-align: center; | ||
font-family: 'Roboto', sans-serif; | ||
font-size: 16px; | ||
font-style: normal; | ||
font-weight: 400; | ||
line-height: 24px; | ||
} | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
apps/schools/domains/circle/components/changeCircleForm/styles/styles.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const TOOLTIP_MARGIN = '47px' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.