Skip to content

Commit

Permalink
RocketChat#759 [EDIT] Укорочена ссылка в приглашении на мероприятие
Browse files Browse the repository at this point in the history
  • Loading branch information
Scarvis committed Nov 9, 2020
1 parent cbdab42 commit 091baed
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 18 deletions.
5 changes: 5 additions & 0 deletions app/api/server/lib/councils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 8 additions & 2 deletions app/api/server/v1/councils.js
Original file line number Diff line number Diff line change
@@ -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 }, {
Expand Down Expand Up @@ -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)));
},
});

5 changes: 3 additions & 2 deletions app/councils/client/views/AddCouncil.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand All @@ -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) => () => {
Expand Down
2 changes: 1 addition & 1 deletion app/councils/client/views/Council.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => [
<Th key={'fio'} color='default'>{t('Council_participant')}</Th>,
Expand Down
8 changes: 4 additions & 4 deletions app/councils/client/views/invite/InvitePageState.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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), []);
Expand Down Expand Up @@ -88,7 +88,7 @@ function InvitePageState() {


return <InvitePageContext.Provider value={value}>
<InviteStepperPage currentStep={currentStep}/>
<InviteStepperPage currentStep={currentStep} council={data}/>
</InvitePageContext.Provider>;
}

Expand Down
6 changes: 3 additions & 3 deletions app/councils/client/views/invite/InviteStepperPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ 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';
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)');
Expand Down Expand Up @@ -55,7 +55,7 @@ function InviteStepperPage({ currentStep = 1 }) {
<Margins all='x16'>
<Tile is='section' flexGrow={1} flexShrink={1}>
<CouncilInfoStep step={1} title={t('Council_info')} active={currentStep === 1}></CouncilInfoStep>
<NewParticipantStep step={2} title={t('Council_participant_info')} active={currentStep === 2}></NewParticipantStep>
<NewParticipantStep step={2} title={t('Council_participant_info')} active={currentStep === 2} council={council}></NewParticipantStep>
</Tile>
</Margins>
</Scrollable>
Expand Down
4 changes: 2 additions & 2 deletions app/councils/client/views/invite/steps/NewParticipantStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down Expand Up @@ -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();

Expand Down
6 changes: 4 additions & 2 deletions app/councils/server/methods/insertOrUpdateCouncil.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion app/models/server/raw/Councils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { BaseRaw } from './BaseRaw';

export class CouncilsRaw extends BaseRaw {

findCouncilByInviteLink(inviteLink, options) {
return this.findOne(inviteLink, options);
}
}
2 changes: 1 addition & 1 deletion client/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down

0 comments on commit 091baed

Please sign in to comment.