From 6a766425d882326e4cafd205b40553386d442775 Mon Sep 17 00:00:00 2001 From: Rahul Rodrigues <rodrigues.rahul77@gmail.com> Date: Mon, 20 Nov 2023 11:26:13 -0500 Subject: [PATCH] extended join url to accept joinFormName to autofill join name (#5526) * extended join url to accept joinFormName to autofill join name * updated existing useEffect joinFormName --- .../components/rooms/room/join/JoinCard.jsx | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/app/javascript/components/rooms/room/join/JoinCard.jsx b/app/javascript/components/rooms/room/join/JoinCard.jsx index e24a2b84..dc7a5a10 100644 --- a/app/javascript/components/rooms/room/join/JoinCard.jsx +++ b/app/javascript/components/rooms/room/join/JoinCard.jsx @@ -18,7 +18,7 @@ import React, { useState, useEffect } from 'react'; import Card from 'react-bootstrap/Card'; import { - Navigate, Link, useParams, + Navigate, Link, useParams, useLocation, } from 'react-router-dom'; import { Button, Col, Row, Stack, Form as RegularForm, @@ -61,6 +61,11 @@ export default function JoinCard() { const path = encodeURIComponent(document.location.pathname); + // get queryParams for JoinFormName + const location = useLocation(); + const queryParams = new URLSearchParams(location.search); + const joinFormName = queryParams.get('joinFormName'); + useEffect(() => { // set cookie to return to if needed const date = new Date(); date.setTime(date.getTime() + (60 * 1000)); // expire the cookie in 1min @@ -86,10 +91,12 @@ export default function JoinCard() { useEffect(() => { // Default Join name to authenticated user full name. - if (currentUser?.name) { + if (joinFormName) { + methods.setValue('name', joinFormName); + } else if (currentUser?.name) { methods.setValue('name', currentUser.name); } - }, [currentUser?.name]); + }, [joinFormName, currentUser?.name]); useEffect(() => { // Room channel subscription: -- GitLab