From 091baedddc01fa4425f89a1a4eed0eba54588cda Mon Sep 17 00:00:00 2001 From: badaev Date: Mon, 9 Nov 2020 09:21:42 +0800 Subject: [PATCH] =?UTF-8?q?RocketChat#759=20[EDIT]=20=D0=A3=D0=BA=D0=BE?= =?UTF-8?q?=D1=80=D0=BE=D1=87=D0=B5=D0=BD=D0=B0=20=D1=81=D1=81=D1=8B=D0=BB?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=B2=20=D0=BF=D1=80=D0=B8=D0=B3=D0=BB=D0=B0?= =?UTF-8?q?=D1=88=D0=B5=D0=BD=D0=B8=D0=B8=20=D0=BD=D0=B0=20=D0=BC=D0=B5?= =?UTF-8?q?=D1=80=D0=BE=D0=BF=D1=80=D0=B8=D1=8F=D1=82=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/server/lib/councils.js | 5 +++++ app/api/server/v1/councils.js | 10 ++++++++-- app/councils/client/views/AddCouncil.js | 5 +++-- app/councils/client/views/Council.js | 2 +- app/councils/client/views/invite/InvitePageState.js | 8 ++++---- app/councils/client/views/invite/InviteStepperPage.js | 6 +++--- .../client/views/invite/steps/NewParticipantStep.js | 4 ++-- app/councils/server/methods/insertOrUpdateCouncil.js | 6 ++++-- app/models/server/raw/Councils.js | 4 +++- client/routes.js | 2 +- 10 files changed, 34 insertions(+), 18 deletions(-) diff --git a/app/api/server/lib/councils.js b/app/api/server/lib/councils.js index 6a0d5c859daf..a882ad33cf20 100644 --- a/app/api/server/lib/councils.js +++ b/app/api/server/lib/councils.js @@ -24,6 +24,11 @@ export async function findOneCouncil(_id) { return cursor; } +export async function findOneCouncilByInviteLink(inviteLink) { + const cursor = await Councils.findCouncilByInviteLink({ inviteLink }, {}); + return cursor; +} + export async function findCouncil(_id) { const cursor = await Councils.findOne({ _id }); return cursor; diff --git a/app/api/server/v1/councils.js b/app/api/server/v1/councils.js index 933e9f9cf522..f1e9eb0a7d9b 100644 --- a/app/api/server/v1/councils.js +++ b/app/api/server/v1/councils.js @@ -1,5 +1,5 @@ import { API } from '../api'; -import { findCouncils, findOneCouncil, findCouncil } from '../lib/councils'; +import { findCouncils, findOneCouncil, findCouncil, findOneCouncilByInviteLink } from '../lib/councils'; import { hasPermission } from '../../../authorization'; API.v1.addRoute('councils.list', { authRequired: true }, { @@ -29,10 +29,16 @@ API.v1.addRoute('councils.getOne', { authRequired: false }, { }, }); +API.v1.addRoute('councils.getOneByInviteLink', { authRequired: false }, { + get() { + const { query } = this.parseJsonQuery(); + return API.v1.success(Promise.await(findOneCouncilByInviteLink(query.inviteLink))); + }, +}); + API.v1.addRoute('councils.findOne', { authRequired: true }, { get() { const { query } = this.parseJsonQuery(); return API.v1.success(Promise.await(findCouncil(query._id))); }, }); - diff --git a/app/councils/client/views/AddCouncil.js b/app/councils/client/views/AddCouncil.js index 6030ae012020..8fdb25406d02 100644 --- a/app/councils/client/views/AddCouncil.js +++ b/app/councils/client/views/AddCouncil.js @@ -202,8 +202,8 @@ function AddCouncilWithNewData({ council, onChange, context }) { const councilData = createCouncilData(date, description, { previousDate, previousDescription, _id }, invitedUsers); const validation = validate(councilData); if (validation.length === 0) { - const _id = await insertOrUpdateCouncil(councilData); - goBack(); + const { _id, ts } = await insertOrUpdateCouncil(councilData); + //console.log(ts.getTime().toString().substr(0, 9)); } validation.forEach((error) => { throw new Error({ type: 'error', message: t('error-the-field-is-required', { field: t(error) }) }); }); }, [_id, dispatchToastMessage, insertOrUpdateCouncil, date, description, invitedUsers, previousDate, previousDescription, previousCouncil, t]); @@ -212,6 +212,7 @@ function AddCouncilWithNewData({ council, onChange, context }) { await saveAction(date, description, invitedUsers); dispatchToastMessage({ type: 'success', message: t('Council_edited') }); onChange(); + goBack(); }, [saveAction, onChange]); const onDeleteParticipantConfirm = (invitedUser) => () => { diff --git a/app/councils/client/views/Council.js b/app/councils/client/views/Council.js index 9ca4e32120e1..25875d31e35c 100644 --- a/app/councils/client/views/Council.js +++ b/app/councils/client/views/Council.js @@ -97,7 +97,7 @@ export function CouncilPage() { } }; - const address = settings.get('Site_Url') + 'invite/council/' + councilId; + const address = settings.get('Site_Url') + 'i/' + data.inviteLink || ''; const header = useMemo(() => [ {t('Council_participant')}, diff --git a/app/councils/client/views/invite/InvitePageState.js b/app/councils/client/views/invite/InvitePageState.js index 97dd278c816e..e32727720c95 100644 --- a/app/councils/client/views/invite/InvitePageState.js +++ b/app/councils/client/views/invite/InvitePageState.js @@ -1,5 +1,5 @@ import React, { createContext, useContext, useEffect, useState, useCallback, useMemo } from 'react'; -import {Box, Skeleton, Scrollable, Margins, InputBox} from '@rocket.chat/fuselage'; +import { Box, Skeleton, Scrollable, Margins, InputBox } from '@rocket.chat/fuselage'; import { useRouteParameter, useRoute } from '../../../../../client/contexts/RouterContext'; import InviteStepperPage from './InviteStepperPage'; @@ -45,10 +45,10 @@ function InvitePageState() { const [currentStep, setCurrentStep, councilId] = useStepRouting(); const query = useMemo(() => ({ - query: JSON.stringify({ _id: councilId }), + query: JSON.stringify({ inviteLink: councilId }), }), [councilId]); - const { data, state, error } = useEndpointDataExperimental('councils.getOne', query); + const { data, state, error } = useEndpointDataExperimental('councils.getOneByInviteLink', query); const goToPreviousStep = useCallback(() => setCurrentStep((currentStep) => (currentStep !== 1 ? currentStep - 1 : currentStep)), []); const goToNextStep = useCallback(() => setCurrentStep((currentStep) => currentStep + 1), []); @@ -88,7 +88,7 @@ function InvitePageState() { return - + ; } diff --git a/app/councils/client/views/invite/InviteStepperPage.js b/app/councils/client/views/invite/InviteStepperPage.js index e600ef4d1c38..f89de673614c 100644 --- a/app/councils/client/views/invite/InviteStepperPage.js +++ b/app/councils/client/views/invite/InviteStepperPage.js @@ -5,7 +5,7 @@ import React from 'react'; import { useTranslation } from '../../../../../client/contexts/TranslationContext'; import { useWipeInitialPageLoading } from '../../../../../client/hooks/useWipeInitialPageLoading'; import ConnectionStatusAlert from '../../../../../client/components/connectionStatus/ConnectionStatusAlert'; -import { errorStep, finalStep, useInvitePageContext } from './InvitePageState'; +import { errorStep, finalStep } from './InvitePageState'; import FinalInviteStep from './steps/FinalInviteStep'; import SideBar from './SideBar'; import NewParticipantStep from './steps/NewParticipantStep'; @@ -13,7 +13,7 @@ import ErrorInviteStep from './steps/ErrorInviteStep'; import CouncilInfoStep from './steps/CouncilInfoStep'; -function InviteStepperPage({ currentStep = 1 }) { +function InviteStepperPage({ currentStep = 1, council = {} }) { useWipeInitialPageLoading(); const t = useTranslation(); const small = useMediaQuery('(max-width: 760px)'); @@ -55,7 +55,7 @@ function InviteStepperPage({ currentStep = 1 }) { - + diff --git a/app/councils/client/views/invite/steps/NewParticipantStep.js b/app/councils/client/views/invite/steps/NewParticipantStep.js index 15c20ea6278d..6b15a8a12843 100644 --- a/app/councils/client/views/invite/steps/NewParticipantStep.js +++ b/app/councils/client/views/invite/steps/NewParticipantStep.js @@ -11,7 +11,7 @@ import { useInvitePageContext } from '../InvitePageState'; import { StepHeader } from '../../../../../../client/views/setupWizard/StepHeader'; import { useRouteParameter } from '../../../../../../client/contexts/RouterContext'; -function NewParticipantStep({ step, title, active }) { +function NewParticipantStep({ step, title, active, council }) { const { goToPreviousStep, goToFinalStep } = useInvitePageContext(); const [newData, setNewData] = useState({ firstName: { value: '', required: true }, @@ -69,7 +69,7 @@ function NewParticipantStep({ step, title, active }) { goToPreviousStep(); }; const addPersonToCouncil = useMethod('addPersonToCouncil'); - const councilId = useRouteParameter('id'); + const councilId = council._id; const handleSubmit = async (event) => { event.preventDefault(); diff --git a/app/councils/server/methods/insertOrUpdateCouncil.js b/app/councils/server/methods/insertOrUpdateCouncil.js index 978c67d04c0d..0cfc9d21488b 100644 --- a/app/councils/server/methods/insertOrUpdateCouncil.js +++ b/app/councils/server/methods/insertOrUpdateCouncil.js @@ -19,9 +19,10 @@ Meteor.methods({ } if (!councilData._id) { - const user = Meteor.user(); + const inviteLink = new Date().getTime().toString().substr(0, 9); + const createCouncil = { ts: new Date(), u: { @@ -30,11 +31,12 @@ Meteor.methods({ }, d: new Date(councilData.d), desc: councilData.desc, + inviteLink, }; const _id = Councils.create(createCouncil); - return _id; + return { _id, ts: createCouncil.ts }; } return Councils.updateCouncil(councilData._id, councilData); diff --git a/app/models/server/raw/Councils.js b/app/models/server/raw/Councils.js index 377bed50742a..c751ae765706 100644 --- a/app/models/server/raw/Councils.js +++ b/app/models/server/raw/Councils.js @@ -1,5 +1,7 @@ import { BaseRaw } from './BaseRaw'; export class CouncilsRaw extends BaseRaw { - + findCouncilByInviteLink(inviteLink, options) { + return this.findOne(inviteLink, options); + } } diff --git a/client/routes.js b/client/routes.js index 3658f05caba6..52071286d305 100755 --- a/client/routes.js +++ b/client/routes.js @@ -103,7 +103,7 @@ FlowRouter.route('/errands/:type?', { }], }); -FlowRouter.route('/invite/council/:id/:step?', { +FlowRouter.route('/i/:id/:step?', { name: 'council-invite', action: () => { renderRouteComponent(() => import('../app/councils/client/views/invite/InviteStepperRoute'));