From 96b19658fbff037394f3010001648bcbed3af61e Mon Sep 17 00:00:00 2001 From: badaev Date: Fri, 27 Nov 2020 16:04:03 +0800 Subject: [PATCH] =?UTF-8?q?RocketChat#822=20[EDIT]=20=D0=9A=D0=BE=D1=80?= =?UTF-8?q?=D1=80=D0=B5=D0=BA=D1=82=D0=BD=D0=BE=D0=B5=20=D0=BE=D1=82=D0=BE?= =?UTF-8?q?=D0=B1=D1=80=D0=B0=D0=B6=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=80=D0=B0?= =?UTF-8?q?=D0=B1=D0=BE=D1=87=D0=B5=D0=B9=20=D0=B3=D1=80=D1=83=D0=BF=D0=BF?= =?UTF-8?q?=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/server/v1/working-groups.js | 7 ++-- app/councils/client/views/AddCouncil.js | 17 +++++++-- app/councils/client/views/Council.js | 18 ++++++--- app/councils/client/views/EditCouncil.js | 38 +++++++++---------- .../views/Participants/CreateParticipant.js | 6 +-- .../views/Participants/ParticipantForm.js | 24 ++++++------ app/lib/server/functions/saveUser.js | 7 ++-- app/protocols/client/views/Protocol.js | 17 +++++++-- .../views/participants/CreateParticipant.js | 4 +- .../views/participants/ParticipantForm.js | 20 ++++++---- app/ui-login/client/login/form.html | 2 +- app/ui-login/client/login/form.js | 10 +++-- .../client/views/EditWorkingGroup.js | 26 ++++++------- app/working-group/client/views/index.js | 18 +++++---- client/account/AccountProfileForm.js | 21 ++++++---- client/account/AccountProfilePage.js | 3 +- client/admin/users/AddUser.js | 3 +- client/admin/users/EditUser.js | 11 +++--- client/admin/users/UserForm.js | 22 +++++++---- 19 files changed, 163 insertions(+), 111 deletions(-) diff --git a/app/api/server/v1/working-groups.js b/app/api/server/v1/working-groups.js index 95ed7404db8a..4293cd948396 100644 --- a/app/api/server/v1/working-groups.js +++ b/app/api/server/v1/working-groups.js @@ -1,10 +1,11 @@ +import { Meteor } from 'meteor/meteor'; +import Busboy from 'busboy'; + import { API } from '../api'; import { findWorkingGroups, findOneWorkingGroup, findWorkingGroup } from '../lib/working-groups'; -import { Meteor } from "meteor/meteor"; import { FileUpload } from '../../../file-upload'; -import Busboy from 'busboy'; -API.v1.addRoute('working-groups.list', { authRequired: true }, { +API.v1.addRoute('working-groups.list', { authRequired: false }, { get() { const { offset, count } = this.getPaginationItems(); const { sort, query } = this.parseJsonQuery(); diff --git a/app/councils/client/views/AddCouncil.js b/app/councils/client/views/AddCouncil.js index d000df3be731..bedbc2cdfd3a 100644 --- a/app/councils/client/views/AddCouncil.js +++ b/app/councils/client/views/AddCouncil.js @@ -37,6 +37,7 @@ const useQuery = ({ text, itemsPerPage, current }, [column, direction]) => useMe }), [text, itemsPerPage, current, column, direction]); export function AddCouncilPage() { + const t = useTranslation(); const [cache, setCache] = useState(); const [params, setParams] = useState({ text: '', current: 0, itemsPerPage: 25 }); const [sort, setSort] = useState(['surname', 'asc']); @@ -46,8 +47,8 @@ export function AddCouncilPage() { const debouncedSort = useDebouncedValue(sort, 500); const query = useQuery(debouncedParams, debouncedSort); + const workingGroups = useEndpointData('working-groups.list', useMemo(() => ({ query: JSON.stringify({ type: { $ne: 'subject' } }) }), [])) || { workingGroups: [] }; const data = useEndpointData('users.list', query) || { users: [] }; - useEffect(() => { if (data.users) { setUsers(data.users); @@ -58,14 +59,22 @@ export function AddCouncilPage() { setCache(new Date()); }, [data]); - return ; + const workingGroupOptions = useMemo(() => { + const res = [[null, t('Not_chosen')]]; + if (workingGroups && workingGroups.workingGroups?.length > 0) { + return res.concat(workingGroups.workingGroups.map((workingGroup) => [workingGroup.title, workingGroup.title])); + } + return res; + }, [workingGroups]); + + return ; } AddCouncilPage.displayName = 'AddCouncilPage'; export default AddCouncilPage; -function AddCouncilWithNewData({ users, setUsers, onChange }) { +function AddCouncilWithNewData({ users, setUsers, onChange, workingGroupOptions }) { const t = useTranslation(); const [context, setContext] = useState('participants'); @@ -169,7 +178,7 @@ function AddCouncilWithNewData({ users, setUsers, onChange }) { } {context === 'participants' && } {context === 'addParticipants' && } - {context === 'newParticipants' && } + {context === 'newParticipants' && } ; diff --git a/app/councils/client/views/Council.js b/app/councils/client/views/Council.js index f204ed09e6a6..ef3d07765505 100644 --- a/app/councils/client/views/Council.js +++ b/app/councils/client/views/Council.js @@ -1,5 +1,6 @@ import React, { useCallback, useMemo, useState } from 'react'; import { ButtonGroup, Button, Field, Icon, Label, TextInput, TextAreaInput, Modal } from '@rocket.chat/fuselage'; +import moment from 'moment'; import Page from '../../../../client/components/basic/Page'; import { useTranslation } from '../../../../client/contexts/TranslationContext'; @@ -8,7 +9,6 @@ import { useEndpointData } from '../../../../client/hooks/useEndpointData'; import { useFormatDateAndTime } from '../../../../client/hooks/useFormatDateAndTime'; import { useMethod } from '../../../../client/contexts/ServerContext'; import { settings } from '../../../settings/client'; -import moment from 'moment'; import { useSetModal } from '../../../../client/contexts/ModalContext'; import { useToastMessageDispatch } from '../../../../client/contexts/ToastMessagesContext'; import { Participants } from './Participants/Participants'; @@ -63,6 +63,7 @@ export function CouncilPage() { const [onCreateParticipantId, setOnCreateParticipantId] = useState(); const [context, setContext] = useState('participants'); const [cache, setCache] = useState(); + const [users, setUsers] = useState([]); const onChange = () => { console.log('onChange'); setCache(new Date()); }; @@ -71,11 +72,10 @@ export function CouncilPage() { }), [councilId]); const data = useEndpointData('councils.findOne', query) || { result: [] }; + const workingGroups = useEndpointData('working-groups.list', useMemo(() => ({ query: JSON.stringify({ type: { $ne: 'subject' } }) }), [])) || { workingGroups: [] }; const invitedUsers = data.invitedUsers || []; - console.log(data); - console.log(invitedUsers); const setModal = useSetModal(); const deleteCouncil = useMethod('deleteCouncil'); @@ -150,6 +150,14 @@ export function CouncilPage() { const onDeleteCouncilClick = () => setModal(() => setModal(undefined)}/>); + const workingGroupOptions = useMemo(() => { + const res = [[null, t('Not_chosen')]]; + if (workingGroups && workingGroups.workingGroups?.length > 0) { + return res.concat(workingGroups.workingGroups.map((workingGroup) => [workingGroup.title, workingGroup.title])); + } + return res; + }, [workingGroups]); + return @@ -202,8 +210,8 @@ export function CouncilPage() { } {context === 'participants' && } - {context === 'addParticipants' && } - {context === 'newParticipants' && } + {context === 'addParticipants' && } + {context === 'newParticipants' && } {context === 'onCreateParticipant' && } diff --git a/app/councils/client/views/EditCouncil.js b/app/councils/client/views/EditCouncil.js index d6327b6d1082..31917fb41eda 100644 --- a/app/councils/client/views/EditCouncil.js +++ b/app/councils/client/views/EditCouncil.js @@ -1,31 +1,17 @@ import React, { useCallback, useState, useMemo, useEffect } from 'react'; -import { - Box, - Button, - ButtonGroup, - Field, - Icon, - TextAreaInput, - TextInput, - Modal, Table, Label, Margins, CheckBox, -} from '@rocket.chat/fuselage'; +import { Box, Button, ButtonGroup, Field, Icon, TextAreaInput, TextInput, Modal, Label } from '@rocket.chat/fuselage'; import DatePicker, { registerLocale } from 'react-datepicker'; import ru from 'date-fns/locale/ru'; +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 { useEndpointData } from '../../../../client/hooks/useEndpointData'; import { useEndpointDataExperimental } from '../../../../client/hooks/useEndpointDataExperimental'; import { useSetModal } from '../../../../client/contexts/ModalContext'; -import { validate, createCouncilData } from './lib'; - -import { useFormatDateAndTime } from '../../../../client/hooks/useFormatDateAndTime'; import { useRouteParameter } from '../../../../client/contexts/RouterContext'; - -import { useMediaQuery } from '@rocket.chat/fuselage-hooks'; - -import { GenericTable, Th } from '../../../../client/components/GenericTable'; -import Page from '../../../../client/components/basic/Page'; +import { validate, createCouncilData } from './lib'; import { AddParticipant } from './Participants/AddParticipant'; import { CreateParticipant } from './Participants/CreateParticipant'; import { Participants } from './Participants/Participants'; @@ -74,6 +60,7 @@ const SuccessModal = ({ title, onClose, ...props }) => { }; export function EditCouncilPage() { + const t = useTranslation(); const context = useRouteParameter('context'); const councilId = useRouteParameter('id'); @@ -82,12 +69,21 @@ export function EditCouncilPage() { }), [councilId]); const { data } = useEndpointDataExperimental('councils.findOne', query) || { result: [] }; + const workingGroups = useEndpointData('working-groups.list', useMemo(() => ({ query: JSON.stringify({ type: { $ne: 'subject' } }) }), [])) || { workingGroups: [] }; const [cache, setCache] = useState(); const onChange = useCallback(() => { setCache(new Date()); }, []); + const workingGroupOptions = useMemo(() => { + const res = [[null, t('Not_chosen')]]; + if (workingGroups && workingGroups.workingGroups?.length > 0) { + return res.concat(workingGroups.workingGroups.map((workingGroup) => [workingGroup.title, workingGroup.title])); + } + return res; + }, [workingGroups]); + if (!data) { return {'error'}; } @@ -96,14 +92,14 @@ export function EditCouncilPage() { data.invitedUsers = []; } - return ; + return ; } EditCouncilPage.displayName = 'EditCouncilPage'; export default EditCouncilPage; -function EditCouncilWithNewData({ council, onChange }) { +function EditCouncilWithNewData({ council, onChange, workingGroupOptions }) { const t = useTranslation(); const { _id, d: previousDate, desc: previousDescription } = council || {}; @@ -322,7 +318,7 @@ function EditCouncilWithNewData({ council, onChange }) { } {context === 'participants' && } {context === 'addParticipants' && } - {context === 'newParticipants' && } + {context === 'newParticipants' && } {context === 'onCreateParticipant' && } diff --git a/app/councils/client/views/Participants/CreateParticipant.js b/app/councils/client/views/Participants/CreateParticipant.js index af6d2455c13b..65770a93d1d4 100644 --- a/app/councils/client/views/Participants/CreateParticipant.js +++ b/app/councils/client/views/Participants/CreateParticipant.js @@ -1,12 +1,12 @@ import React, { useCallback, useMemo } from 'react'; import { Box, Button, Field } from '@rocket.chat/fuselage'; + import { useTranslation } from '../../../../../client/contexts/TranslationContext'; -import { useEndpointData } from '../../../../../client/hooks/useEndpointData'; import { useForm } from '../../../../../client/hooks/useForm'; import { useEndpointAction } from '../../../../../client/hooks/useEndpointAction'; import ParticipantForm from './ParticipantForm'; -export function CreateParticipant({ goTo, close, ...props }) { +export function CreateParticipant({ goTo, close, workingGroupOptions, ...props }) { const t = useTranslation(); const { @@ -46,5 +46,5 @@ export function CreateParticipant({ goTo, close, ...props }) { , [close, t, handleSave]); - return ; + return ; } diff --git a/app/councils/client/views/Participants/ParticipantForm.js b/app/councils/client/views/Participants/ParticipantForm.js index 6110d4f9e866..04fffb2ec81a 100644 --- a/app/councils/client/views/Participants/ParticipantForm.js +++ b/app/councils/client/views/Participants/ParticipantForm.js @@ -1,18 +1,16 @@ -import React, { useCallback, useMemo, useState } from 'react'; +import React, { useCallback, useMemo } from 'react'; import { Field, TextInput, Icon, - FieldGroup, Scrollable, - Select, Margins, Box, ButtonGroup, Button, CheckBox, + Select, } from '@rocket.chat/fuselage'; import { useTranslation } from '../../../../../client/contexts/TranslationContext'; import { isEmail } from '../../../../utils/lib/isEmail.js'; -import VerticalBar from '../../../../../client/components/basic/VerticalBar'; -export default function ParticipantForm({ formValues, formHandlers, availableRoles, append, ...props }) { +export default function ParticipantForm({ formValues, formHandlers, workingGroupOptions, availableRoles, append, ...props }) { const t = useTranslation(); const { @@ -37,12 +35,16 @@ export default function ParticipantForm({ formValues, formHandlers, availableRol handleWorkingGroup, } = formHandlers; - const workingGroupOptions = useMemo(() => [ - ['Не выбрано', t('Not_chosen')], - ['Члены рабочей группы', 'Члены рабочей группы'], - ['Представители субъектов Российской Федерации', 'Представители субъектов Российской Федерации'], - ['Иные участники', 'Иные участники'], - ], [t]); + // const workingGroupOptions = useMemo(() => { + // const res = [[null, t('Not_chosen')]]; + // return res.concat(workingGroups?.map((workingGroup) => [workingGroup.title, workingGroup.title])); + // }, [workingGroups]); + // const workingGroupOptions = useMemo(() => [ + // ['Не выбрано', t('Not_chosen')], + // ['Члены рабочей группы', 'Члены рабочей группы'], + // ['Представители субъектов Российской Федерации', 'Представители субъектов Российской Федерации'], + // ['Иные участники', 'Иные участники'], + // ], [t]); return e.preventDefault(), [])} { ...props }> diff --git a/app/lib/server/functions/saveUser.js b/app/lib/server/functions/saveUser.js index 682ab9e6cb65..648d91fceef8 100644 --- a/app/lib/server/functions/saveUser.js +++ b/app/lib/server/functions/saveUser.js @@ -198,15 +198,16 @@ function validateUserEditing(userId, userData) { } function validateParticipantData(userId, userData) { + // eslint-disable-next-line react-hooks/rules-of-hooks if (userData._id && userId !== userData._id && !hasPermission(userId, 'edit-other-user-info')) { - throw new Meteor.Error('error-action-not-allowed', 'Editing user is not allowed', { + throw new Meteor.Error('error-action-not-allowed', 'Editing_user_is_not_allowed', { method: 'insertOrUpdateUser', action: 'Editing_user', }); } if (!userData._id && !hasPermission(userId, 'create-user')) { - throw new Meteor.Error('error-action-not-allowed', 'Adding user is not allowed', { + throw new Meteor.Error('error-action-not-allowed', 'Adding_user_is_not_allowed', { method: 'insertOrUpdateUser', action: 'Adding_user', }); @@ -220,7 +221,7 @@ function validateParticipantData(userId, userData) { // } if (!userData._id && !s.trim(userData.username)) { - throw new Meteor.Error('error-the-field-is-required', 'The field Username is required', { + throw new Meteor.Error('error-the-field-is-required', 'The_field_is_required', { method: 'insertOrUpdateUser', field: 'Username', }); diff --git a/app/protocols/client/views/Protocol.js b/app/protocols/client/views/Protocol.js index 3377eb1664d6..180a92030e3b 100644 --- a/app/protocols/client/views/Protocol.js +++ b/app/protocols/client/views/Protocol.js @@ -14,9 +14,9 @@ import { AddSection } from './AddSection'; import { AddItem } from './AddItem'; import { EditSection } from './EditSection'; import { EditItem } from './EditItem'; -import { Participants } from '../views/participants/Participants'; -import { AddParticipant } from '../views/participants/AddParticipant'; -import { CreateParticipant } from '../views/participants/CreateParticipant'; +import { Participants } from './participants/Participants'; +import { AddParticipant } from './participants/AddParticipant'; +import { CreateParticipant } from './participants/CreateParticipant'; import { popover } from '../../../ui-utils/client/lib/popover'; import VerticalBar from '../../../../client/components/basic/VerticalBar'; @@ -78,6 +78,7 @@ export function ProtocolPage() { }), [protocolId, cache]); const data = useEndpointData('protocols.findOne', query) || {}; + const workingGroups = useEndpointData('working-groups.list', useMemo(() => ({ query: JSON.stringify({ type: { $ne: 'subject' } }) }), [])) || { workingGroups: [] }; const title = t('Protocol').concat(' ').concat(data.num).concat(' ').concat(t('Date_to')).concat(' ').concat(formatDate(data.d)); @@ -272,6 +273,14 @@ export function ProtocolPage() { window.history.back(); }; + const workingGroupOptions = useMemo(() => { + const res = [[null, t('Not_chosen')]]; + if (workingGroups && workingGroups.workingGroups?.length > 0) { + return res.concat(workingGroups.workingGroups.map((workingGroup) => [workingGroup.title, workingGroup.title])); + } + return res; + }, [workingGroups]); + return @@ -320,7 +329,7 @@ export function ProtocolPage() { {context === 'edit-item' && } {context === 'participants' && } {context === 'add-participant' && } - {context === 'create-participant' && } + {context === 'create-participant' && } } ; } diff --git a/app/protocols/client/views/participants/CreateParticipant.js b/app/protocols/client/views/participants/CreateParticipant.js index 7fefe54ac912..30bd57fd0c96 100644 --- a/app/protocols/client/views/participants/CreateParticipant.js +++ b/app/protocols/client/views/participants/CreateParticipant.js @@ -6,7 +6,7 @@ import { useForm } from '../../../../../client/hooks/useForm'; import { useEndpointAction } from '../../../../../client/hooks/useEndpointAction'; import ParticipantForm from './ParticipantForm'; -export function CreateParticipant({ goTo, close, ...props }) { +export function CreateParticipant({ goTo, close, workingGroupOptions, ...props }) { const t = useTranslation(); const roleData = useEndpointData('roles.list', '') || {}; @@ -50,5 +50,5 @@ export function CreateParticipant({ goTo, close, ...props }) { , [hasUnsavedChanges, close, t, handleSave]); - return ; + return ; } diff --git a/app/protocols/client/views/participants/ParticipantForm.js b/app/protocols/client/views/participants/ParticipantForm.js index 4e7d2f5a13cd..9379631f642a 100644 --- a/app/protocols/client/views/participants/ParticipantForm.js +++ b/app/protocols/client/views/participants/ParticipantForm.js @@ -8,10 +8,10 @@ import { } from '@rocket.chat/fuselage'; import { useTranslation } from '../../../../../client/contexts/TranslationContext'; -import { isEmail } from '../../../../../app/utils/lib/isEmail.js'; +import { isEmail } from '../../../../utils/lib/isEmail.js'; import VerticalBar from '../../../../../client/components/basic/VerticalBar'; -export default function ParticipantForm({ formValues, formHandlers, availableRoles, append, prepend, ...props }) { +export default function ParticipantForm({ formValues, formHandlers, workingGroupOptions, availableRoles, append, prepend, ...props }) { const t = useTranslation(); const { @@ -36,12 +36,16 @@ export default function ParticipantForm({ formValues, formHandlers, availableRol handleWorkingGroup, } = formHandlers; - const workingGroupOptions = useMemo(() => [ - ['Не выбрано', t('Not_chosen')], - ['Члены рабочей группы', 'Члены рабочей группы'], - ['Представители субъектов Российской Федерации', 'Представители субъектов Российской Федерации'], - ['Иные участники', 'Иные участники'], - ], [t]); + // const workingGroupOptions = useMemo(() => { + // const res = [[null, t('Not_chosen')]]; + // return res.concat(workingGroups?.map((workingGroup) => [workingGroup.title, workingGroup.title])); + // }, [workingGroups]); + // const workingGroupOptions = useMemo(() => [ + // ['Не выбрано', t('Not_chosen')], + // ['Члены рабочей группы', 'Члены рабочей группы'], + // ['Представители субъектов Российской Федерации', 'Представители субъектов Российской Федерации'], + // ['Иные участники', 'Иные участники'], + // ], [t]); return e.preventDefault(), [])} { ...props }> diff --git a/app/ui-login/client/login/form.html b/app/ui-login/client/login/form.html index d2f1480ed42c..9fa36929fd7a 100644 --- a/app/ui-login/client/login/form.html +++ b/app/ui-login/client/login/form.html @@ -116,7 +116,7 @@

{{{_ "Registration_Succeeded"}}}

{{#each workingGroup in workingGroups}} - + {{/each}} diff --git a/app/ui-login/client/login/form.js b/app/ui-login/client/login/form.js index c294113f03f0..609f767edd8e 100644 --- a/app/ui-login/client/login/form.js +++ b/app/ui-login/client/login/form.js @@ -12,7 +12,6 @@ import { APIClient } from '../../../utils/client'; import { settings } from '../../../settings'; import { callbacks } from '../../../callbacks'; import { t, handleError } from '../../../utils'; -import { useEndpointData } from '/client/hooks/useEndpointData'; const getLoginExample = (surname, name, patronymic) => { if (!surname || !name) { @@ -35,7 +34,7 @@ const getLoginExample = (surname, name, patronymic) => { for (const kr in L) { reg += kr; } - reg = new RegExp('[' + reg + ']', 'g'); + reg = new RegExp(['[', reg, ']'].join(''), 'g'); const translate = function(a) { return a in L ? L[a] : a; }; @@ -269,7 +268,12 @@ Template.loginForm.onCreated(function() { this.loading = new ReactiveVar(false); this.loginExample = new ReactiveVar(''); this.registerStepOneForm = new ReactiveVar({}); - this.workingGroups = new ReactiveVar(['Члены рабочей группы', 'Представители субъектов Российской Федерации', 'Иные участники']); + this.workingGroups = new ReactiveVar([]); + + this.autorun(async () => { + const { workingGroups } = await APIClient.v1.get(`working-groups.list?&query=${ JSON.stringify({ type: { $ne: 'subject' } }) }`); + return this.workingGroups.set(workingGroups); + }); Tracker.autorun(() => { const Accounts_CustomFields = settings.get('Accounts_CustomFields'); diff --git a/app/working-group/client/views/EditWorkingGroup.js b/app/working-group/client/views/EditWorkingGroup.js index fc889be23ebd..180311e71faa 100644 --- a/app/working-group/client/views/EditWorkingGroup.js +++ b/app/working-group/client/views/EditWorkingGroup.js @@ -13,19 +13,17 @@ import { Modal, } from '@rocket.chat/fuselage'; import ru from 'date-fns/locale/ru'; - import { registerLocale } from 'react-datepicker'; -registerLocale('ru', ru); import { useTranslation } from '../../../../client/contexts/TranslationContext'; import { useMethod } from '../../../../client/contexts/ServerContext'; import { useToastMessageDispatch } from '../../../../client/contexts/ToastMessagesContext'; import { useEndpointDataExperimental, ENDPOINT_STATES } from '../../../../client/hooks/useEndpointDataExperimental'; -import { validate, createWorkingGroupData } from './lib'; import { useSetModal } from '../../../../client/contexts/ModalContext'; import VerticalBar from '../../../../client/components/basic/VerticalBar'; -import { useEndpointData } from '/client/hooks/useEndpointData'; +import { validate, createWorkingGroupData } from './lib'; +registerLocale('ru', ru); require('react-datepicker/dist/react-datepicker.css'); const DeleteWarningModal = ({ onDelete, onCancel, ...props }) => { @@ -67,7 +65,7 @@ const SuccessModal = ({ onClose, ...props }) => { ; }; -export function EditWorkingGroup({ _id, cache, onChange, ...props }) { +export function EditWorkingGroup({ _id, workingGroupOptions, cache, onChange, ...props }) { const queryUser = useMemo(() => ({ query: JSON.stringify({ _id }), }), [_id, cache]); @@ -94,10 +92,10 @@ export function EditWorkingGroup({ _id, cache, onChange, ...props }) { return {error}; } - return ; + return ; } -function EditWorkingGroupWithData({ close, onChange, workingGroupUser, ...props }) { +function EditWorkingGroupWithData({ close, workingGroupOptions, onChange, workingGroupUser, ...props }) { const t = useTranslation(); const dispatchToastMessage = useToastMessageDispatch(); @@ -109,7 +107,7 @@ function EditWorkingGroupWithData({ close, onChange, workingGroupUser, ...props patronymic: previousPatronymic, position: previousPosition, phone: previousPhone, - email: previousEmail + email: previousEmail, } = workingGroupUser || {}; const previousWorkingGroupUser = workingGroupUser || {}; @@ -224,12 +222,12 @@ function EditWorkingGroupWithData({ close, onChange, workingGroupUser, ...props const openConfirmDelete = () => setModal(() => setModal(undefined)}/>); - const workingGroupOptions = useMemo(() => [ - ['Не выбрано', t('Not_chosen')], - ['Члены рабочей группы', 'Члены рабочей группы'], - ['Представители субъектов Российской Федерации', 'Представители субъектов Российской Федерации'], - ['Иные участники', 'Иные участники'], - ], [t]); + // const workingGroupOptions = useMemo(() => [ + // ['Не выбрано', t('Not_chosen')], + // ['Члены рабочей группы', 'Члены рабочей группы'], + // ['Представители субъектов Российской Федерации', 'Представители субъектов Российской Федерации'], + // ['Иные участники', 'Иные участники'], + // ], [t]); const getShortFio = (surname, name, patronymic) => [surname, name.charAt(0).toUpperCase(), patronymic ? patronymic.charAt(0).toUpperCase() : ''].join(' '); diff --git a/app/working-group/client/views/index.js b/app/working-group/client/views/index.js index 52f707d6f2b7..b4470e265966 100644 --- a/app/working-group/client/views/index.js +++ b/app/working-group/client/views/index.js @@ -9,7 +9,6 @@ import { useRoute, useRouteParameter } from '../../../../client/contexts/RouterC import VerticalBar from '../../../../client/components/basic/VerticalBar'; import { useEndpointData } from '../../../../client/hooks/useEndpointData'; import { useMethod } from '../../../../client/contexts/ServerContext'; - import { WorkingGroups } from './WorkingGroups'; import { AddWorkingGroup } from './AddWorkingGroup'; import { EditWorkingGroup } from './EditWorkingGroup'; @@ -39,6 +38,7 @@ export function WorkingGroupPage() { const queryUser = useQueryUser(debouncedParams, debouncedSort, cache); const data = useEndpointData('users.list', queryUser) || {}; + const workingGroups = useEndpointData('working-groups.list', useMemo(() => ({ query: JSON.stringify({ type: { $ne: 'subject' } }) }), [])) || { workingGroups: [] }; const router = useRoute(routeName); @@ -103,6 +103,14 @@ export function WorkingGroupPage() { window.history.back(); }; + const workingGroupOptions = useMemo(() => { + const res = [[null, t('Not_chosen')]]; + if (workingGroups && workingGroups.workingGroups?.length > 0) { + return res.concat(workingGroups.workingGroups.map((workingGroup) => [workingGroup.title, workingGroup.title])); + } + return res; + }, [workingGroups]); + return @@ -116,12 +124,6 @@ export function WorkingGroupPage() { - {/**/} - {/**/} @@ -137,7 +139,7 @@ export function WorkingGroupPage() { { context === 'new' && t('Working_group_add') } - {context === 'edit' && } + {context === 'edit' && } {context === 'new' && } } diff --git a/client/account/AccountProfileForm.js b/client/account/AccountProfileForm.js index d244bba6013d..3df5466e081f 100644 --- a/client/account/AccountProfileForm.js +++ b/client/account/AccountProfileForm.js @@ -13,7 +13,7 @@ import UserStatusMenu from '../components/basic/userStatus/UserStatusMenu'; const STATUS_TEXT_MAX_LENGTH = 120; -export default function AccountProfileForm({ values, handlers, user, data, settings, onSaveStateChange, ...props }) { +export default function AccountProfileForm({ values, handlers, user, workingGroups, data, settings, onSaveStateChange, ...props }) { const t = useTranslation(); const dispatchToastMessage = useToastMessageDispatch(); @@ -156,12 +156,19 @@ export default function AccountProfileForm({ values, handlers, user, data, setti !!statusTextError, ].filter(Boolean); - const workingGroupOptions = useMemo(() => [ - ['Не выбрано', t('Not_chosen')], - ['Члены рабочей группы', 'Члены рабочей группы'], - ['Представители субъектов Российской Федерации', 'Представители субъектов Российской Федерации'], - ['Иные участники', 'Иные участники'], - ], [t]); + const workingGroupOptions = useMemo(() => { + const res = [[null, t('Not_chosen')]]; + if (workingGroups?.length > 0) { + return res.concat(workingGroups.map((workingGroup) => [workingGroup.title, workingGroup.title])); + } + return res; + }, [workingGroups]); + // const workingGroupOptions = useMemo(() => [ + // ['Не выбрано', t('Not_chosen')], + // ['Члены рабочей группы', 'Члены рабочей группы'], + // ['Представители субъектов Российской Федерации', 'Представители субъектов Российской Федерации'], + // ['Иные участники', 'Иные участники'], + // ], [t]); useEffect(() => { onSaveStateChange(canSave); diff --git a/client/account/AccountProfilePage.js b/client/account/AccountProfilePage.js index c0ee2b464f27..4a141d6c5727 100644 --- a/client/account/AccountProfilePage.js +++ b/client/account/AccountProfilePage.js @@ -75,6 +75,7 @@ const AccountProfilePage = () => { query: JSON.stringify({ _id: userId }), }), [userId]); const data = useEndpointData('users.getOne', query) || { result: [] }; + const workingGroups = useEndpointData('working-groups.list', useMemo(() => ({ query: JSON.stringify({ type: { $ne: 'subject' } }) }), [])) || { workingGroups: [] }; const [canSave, setCanSave] = useState(true); const setModal = useSetModal(); @@ -323,7 +324,7 @@ const AccountProfilePage = () => { - +