Skip to content

Commit

Permalink
RocketChat#821 [FIX] Правки в форме подачи документов
Browse files Browse the repository at this point in the history
  • Loading branch information
Scarvis committed Dec 26, 2020
1 parent 4e6f465 commit 9d9153a
Show file tree
Hide file tree
Showing 12 changed files with 726 additions and 98 deletions.
12 changes: 12 additions & 0 deletions app/utils/client/methods/checkNumber.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// format = 2,2,3
export const checkNumberWithDot = (value, prevValue) => {
if (!value || value.length < 1 || value[0] === '.') {
return null;
}
let str = value;
if (value[value.length - 1] === '.') {
str = value.slice(0, value.length - 1);
}

return str.match('^\\d+(\\.\\d+)*$');
};
7 changes: 6 additions & 1 deletion app/working-group/client/views/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,26 @@ export function createWorkingGroupCompositionData(title, previousData) {
export function validateWorkingGroupRequestData(workingGroupRequestData) {
const errors = [];

if (!workingGroupRequestData.number) {
errors.push('number');
}

if (!workingGroupRequestData.desc) {
errors.push('desc');
}

return errors;
}

export function createWorkingGroupRequestData(desc, previousData) {
export function createWorkingGroupRequestData(number, desc, previousData) {
const workingGroupRequestData = {
};

if (previousData) {
workingGroupRequestData._id = previousData._id;
}

workingGroupRequestData.number = number;
workingGroupRequestData.desc = desc;

return workingGroupRequestData;
Expand Down
111 changes: 79 additions & 32 deletions app/working-group/client/views/requests/AddRequest.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import React, { useCallback, useMemo, useState } from 'react';
import { Button, ButtonGroup, Field, TextAreaInput } from '@rocket.chat/fuselage';
import { Button, ButtonGroup, Field, TextInput, TextAreaInput } from '@rocket.chat/fuselage';

import Page from '../../../../../client/components/basic/Page';
import { useTranslation } from '../../../../../client/contexts/TranslationContext';
import { useMethod } from '../../../../../client/contexts/ServerContext';
import { useToastMessageDispatch } from '../../../../../client/contexts/ToastMessagesContext';
import { createWorkingGroupRequestData, validateWorkingGroupRequestData } from '../lib';
import VerticalBar from '../../../../../client/components/basic/VerticalBar';
import { checkNumberWithDot } from '../../../../utils/client/methods/checkNumber';

export function AddRequest({ editData, onChange }) {
const data = {
_id: '',
_id: null,
number: '',
desc: '',
mails: [],
};
Expand All @@ -18,70 +20,115 @@ export function AddRequest({ editData, onChange }) {
return <AddRequestWithData request={editData ?? data} onChange={onChange}/>;
}

function AddRequestWithData({ request, onChange }) {
function AddRequestWithData({ request, onChange, ...props }) {
const t = useTranslation();
const dispatchToastMessage = useToastMessageDispatch();

const { _id, number: previousNumber, desc: previousDescription } = request || {};
const previousRequest = request || {};

const [number, setNumber] = useState(previousNumber);
const [description, setDescription] = useState(previousDescription);
//const [number, setNumber] = useState(previousNumber);

const insertOrUpdateWorkingGroupRequest = useMethod('insertOrUpdateWorkingGroupRequest');
const goBack = () => {
window.history.back();
};

const hasUnsavedChanges = useMemo(() => previousDescription !== description,
[description, previousDescription]);
const hasUnsavedChanges = useMemo(() => (description !== '' && number !== '') && (previousDescription !== description || previousNumber !== number),
[description, previousDescription, number, previousNumber]);

const resetData = () => {
setDescription(previousDescription);
//setNumber(previousNumber);
setNumber(previousNumber);
onChange();
};

const saveAction = useCallback(async (description) => {
const requestData = createWorkingGroupRequestData(description, { previousDescription, _id });
const filterNumber = (value) => {
if (checkNumberWithDot(value, number) !== null || value === '') {
setNumber(value);
}
};

const saveAction = useCallback(async (number, description) => {
console.log(number);
console.log(description);
const requestData = createWorkingGroupRequestData(number, description, { previousNumber, previousDescription, _id });
const validation = validateWorkingGroupRequestData(requestData);
if (validation.length === 0) {
await insertOrUpdateWorkingGroupRequest(requestData);
}
validation.forEach((error) => { throw new Error({ type: 'error', message: t('error-the-field-is-required', { field: t(error) }) }); });
}, [_id, dispatchToastMessage, insertOrUpdateWorkingGroupRequest, description, previousDescription, previousRequest, t]);
}, [_id, dispatchToastMessage, insertOrUpdateWorkingGroupRequest, number, description, previousNumber, previousDescription, previousRequest, t]);

const handleSaveRequest = useCallback(async () => {
await saveAction(description);
dispatchToastMessage({ type: 'success', message: t('Council_edited') });
await saveAction(number, description);
if (!request._id) {
dispatchToastMessage({
type: 'success',
message: t('Working_group_request_added'),
});
} else {
dispatchToastMessage({
type: 'success',
message: t('Working_group_request_edited'),
});
}
onChange();
goBack();
}, [saveAction, onChange]);

return <Page flexDirection='row'>
<Page>
<Page.Content>
<ButtonGroup mis='auto'>
return <VerticalBar.ScrollableContent {...props}>
<Field>
<Field.Label>{t('Number')}</Field.Label>
<Field.Row>
<TextInput border='1px solid #4fb0fc' value={number} onChange={(e) => filterNumber(e.currentTarget.value)} placeholder={t('Number')}/>
</Field.Row>
</Field>
<Field>
<Field.Label>{t('Description')}</Field.Label>
<Field.Row>
<TextAreaInput style={ { whiteSpace: 'normal' } } row='10' border='1px solid #4fb0fc' value={description} onChange={(e) => setDescription(e.currentTarget.value)} placeholder={t('Description')} />
</Field.Row>
</Field>
<Field>
<Field.Row>
<ButtonGroup stretch w='full'>
<Button primary small aria-label={t('Cancel')} disabled={!hasUnsavedChanges} onClick={resetData}>
{t('Cancel')}
</Button>
<Button primary small aria-label={t('Save')} disabled={!hasUnsavedChanges} onClick={handleSaveRequest}>
{t('Save')}
</Button>
</ButtonGroup>
{/*<Field mbe='x8'>*/}
{/* <Field.Label>{t('Number')}</Field.Label>*/}
{/* <Field.Row>*/}
{/* <TextInput border='1px solid #4fb0fc' value={number} onChange={(e) => setNumber(e.currentTarget.value)} placeholder={t('Number')} />*/}
{/* </Field.Row>*/}
{/*</Field>*/}
<Field mbe='x8'>
<Field.Label>{t('Description')}</Field.Label>
<Field.Row>
<TextAreaInput style={ { whiteSpace: 'normal' } } row='10' border='1px solid #4fb0fc' value={description} onChange={(e) => setDescription(e.currentTarget.value)} placeholder={t('Description')} />
</Field.Row>
</Field>
</Page.Content>
</Page>
</Page>;
</Field.Row>
</Field>
</VerticalBar.ScrollableContent>;

// return <Page flexDirection='row'>
// <Page>
// <Page.Content>
// <ButtonGroup mis='auto'>
// <Button primary small aria-label={t('Cancel')} disabled={!hasUnsavedChanges} onClick={resetData}>
// {t('Cancel')}
// </Button>
// <Button primary small aria-label={t('Save')} disabled={!hasUnsavedChanges} onClick={handleSaveRequest}>
// {t('Save')}
// </Button>
// </ButtonGroup>
// {/*<Field mbe='x8'>*/}
// {/* <Field.Label>{t('Number')}</Field.Label>*/}
// {/* <Field.Row>*/}
// {/* <TextInput border='1px solid #4fb0fc' value={number} onChange={(e) => setNumber(e.currentTarget.value)} placeholder={t('Number')} />*/}
// {/* </Field.Row>*/}
// {/*</Field>*/}
// <Field mbe='x8'>
// <Field.Label>{t('Description')}</Field.Label>
// <Field.Row>
// <TextAreaInput style={ { whiteSpace: 'normal' } } row='10' border='1px solid #4fb0fc' value={description} onChange={(e) => setDescription(e.currentTarget.value)} placeholder={t('Description')} />
// </Field.Row>
// </Field>
// </Page.Content>
// </Page>
// </Page>;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Box, Tile } from '@rocket.chat/fuselage';
import { Box, Tile, Icon } from '@rocket.chat/fuselage';
import React from 'react';

import { useTranslation } from '../../../../../../../client/contexts/TranslationContext';
Expand All @@ -9,7 +9,10 @@ function FinalInviteStep() {
return <Box is='section' width='full' maxWidth='x480' margin='auto'>
<Tile is='main' padding='x40'>
<Box margin='x32'>
<Box is='h1' fontScale='h1' marginBlockEnd='x32'>{t('Your_information_accepted')}</Box>
<Box is='h1' fontScale='h1' marginBlockEnd='x32'>
<Icon color='success' name='checkmark-circled' size={20}/>
{t('Working_group_request_your_information_accepted')}
</Box>
</Box>
</Tile>
</Box>;
Expand Down
Loading

0 comments on commit 9d9153a

Please sign in to comment.