Skip to content

Commit

Permalink
Merge pull request #394 from memser-spaceport/develop
Browse files Browse the repository at this point in the history
Develop to Staging
  • Loading branch information
madan-ideas2it authored Nov 26, 2024
2 parents 6898897 + 06d844e commit 52864d6
Show file tree
Hide file tree
Showing 14 changed files with 87 additions and 61 deletions.
24 changes: 16 additions & 8 deletions app/irl/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export default async function Page({ searchParams }: any) {
isUserGoing={isUserGoing as boolean}
searchParams={searchParams}
currentEventNames={currentEventNames}
locationEvents={eventDetails}
/>
</section>
</div>
Expand Down Expand Up @@ -84,10 +85,12 @@ const getPageData = async (searchParams: any) => {
const eventDetails = searchParams?.location ? locationDetails.find((loc: any) => loc.location.split(',')[0].trim() === searchParams.location) : locationDetails[0];
const { uid, location: name, pastEvents } = eventDetails;

//check correct event type
if (searchParams?.type) {
isEventActive = ['upcoming', 'past'].includes(searchParams?.type);
}

//check correct event slug
if (searchParams?.event) {
const eventResult = locationDetails.flatMap((item: { pastEvents: any[]; upcomingEvents: any[] }) => [
...item.pastEvents.map((event) => ({ ...event })),
Expand All @@ -105,14 +108,21 @@ const getPageData = async (searchParams: any) => {

// Determine event type and fetch event guest data
const eventType = searchParams?.type === 'past' ? 'past' : searchParams?.type === 'upcoming' ? 'upcoming' : '';

if (searchParams?.type === 'past' && !searchParams?.event) {
searchParams.event = pastEvents[0]?.slugURL;
}

const currentEvents = eventType === 'upcoming' ? eventDetails?.upcomingEvents : eventType === 'past' ? eventDetails?.pastEvents : eventDetails?.events;
const currentEventNames = currentEvents?.map((item: any) => item.name); // Get current event names

// Set default event if location has only past events
if (!eventType) {
if (eventDetails?.upcomingEvents?.length === 0 && eventDetails?.pastEvents?.length > 0) {
searchParams.event = pastEvents[0]?.slugURL;
searchParams.type = 'past';
}
} else {
if (eventType === 'past' && !searchParams?.event) {
searchParams.event = pastEvents[0]?.slugURL;
}
}

// Proceed with API calls only after currentEventNames is set
const [events, currentGuestResponse, topics, loggedInUserEvents] = await Promise.all([
getGuestsByLocation(uid, parseSearchParams(searchParams, currentEvents), authToken, currentEventNames),
Expand All @@ -126,13 +136,11 @@ const getPageData = async (searchParams: any) => {
}

let guestDetails = events as any;
const selectedTypeEvents = eventType === 'past' ? eventDetails.pastEvents : eventDetails.upcomingEvents;
const selectedTypeEvents = (eventType === 'past' || eventDetails?.upcomingEvents?.length === 0 && eventDetails?.pastEvents?.length > 0) ? eventDetails.pastEvents : eventDetails.upcomingEvents;

guestDetails.events = selectedTypeEvents;
guestDetails.currentGuest = currentGuestResponse?.guests?.[0]?.memberUid === userInfo?.uid ? currentGuestResponse?.guests?.[0] : null;
guestDetails.isUserGoing = selectedTypeEvents?.some((event: any) => loggedInUserEvents?.some((userEvent: any) => userEvent?.uid === event?.uid));


guestDetails.topics = topics;
guestDetails.eventsForFilter = getFilteredEventsForUser(loggedInUserEvents, currentEvents, isLoggedIn, userInfo);

Expand Down
7 changes: 4 additions & 3 deletions components/page/irl/add-edit-attendee/attendee-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import SearchableSingleSelect from '@/components/form/searchable-single-select';
import SingleSelectWithImage from '@/components/form/single-select-with-image';
import { getMember, getMembersForAttendeeForm, getMembersForProjectForm } from '@/services/members.service';
import { getMemberPreferences } from '@/services/preferences.service';
import { IIrlAttendeeFormErrors, IIrlLocation } from '@/types/irl.types';
import { IIrlAttendeeFormErrors, IIrlEvent, IIrlLocation } from '@/types/irl.types';
import { IUserInfo } from '@/types/shared.types';
import { getParsedValue, getUserInfoFromLocal, triggerLoader } from '@/utils/common.utils';
import { EVENTS, IAM_GOING_POPUP_MODES, IRL_ATTENDEE_FORM_ERRORS } from '@/utils/constants';
Expand All @@ -21,6 +21,7 @@ interface IAttendeeForm {
setFormInitialValues: SetStateAction<any>;
location: IIrlLocation;
eventType: string;
gatherings: IIrlEvent[];
}

const AttendeeDetails = (props: IAttendeeForm) => {
Expand All @@ -32,6 +33,7 @@ const AttendeeDetails = (props: IAttendeeForm) => {
const setFormInitialValues = props?.setFormInitialValues;
const location = props?.location;
const eventType = props?.eventType ?? '';
const gatherings = props?.gatherings ?? [];

const [initialContributors, setInitialContributors] = useState([]);
const [initialTeams, setInitialTeams] = useState(initialValues?.teams ?? []);
Expand Down Expand Up @@ -86,9 +88,8 @@ const AttendeeDetails = (props: IAttendeeForm) => {
const fetchGuestDetails = async () => {
try {
let result = await getGuestDetail(selectedMember.uid ?? '', location.uid, authToken, eventType);

if (result.length>0) {
const formData = transformGuestDetail(result);
const formData = transformGuestDetail(result, gatherings);

updateMemberDetails(false);
setSelectedTeam({name: formData?.teamName,
Expand Down
2 changes: 1 addition & 1 deletion components/page/irl/add-edit-attendee/attendee-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ const AttendeeForm: React.FC<IAttendeeForm> = (props) => {
<h2 className="atndform__bdy__ttl">Enter Attendee Details</h2>
<AttendeeFormErrors errors={errors} />
<div>
<AttendeeDetails setFormInitialValues={setFormInitialValues} initialValues={formInitialValues} allGuests={allGuests} memberInfo={userInfo} mode={mode} errors={errors} location={selectedLocation} eventType = {eventType}/>
<AttendeeDetails gatherings={gatherings} setFormInitialValues={setFormInitialValues} initialValues={formInitialValues} allGuests={allGuests} memberInfo={userInfo} mode={mode} errors={errors} location={selectedLocation} eventType = {eventType}/>
</div>
<div>
<Gatherings
Expand Down
18 changes: 11 additions & 7 deletions components/page/irl/attendee-list/attendees-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import AttendeeTableHeader from './attendee-table-header';
import { IUserInfo } from '@/types/shared.types';
import { IAnalyticsGuestLocation, IGuest, IGuestDetails } from '@/types/irl.types';
import usePagination from '@/hooks/irl/use-pagination';
import { getFilteredEventsForUser, parseSearchParams } from '@/utils/irl.utils';
import { checkAdminInAllEvents, getFilteredEventsForUser, parseSearchParams } from '@/utils/irl.utils';
import TableLoader from '@/components/core/table-loader';

interface IAttendeeList {
Expand All @@ -30,6 +30,7 @@ interface IAttendeeList {
isUserGoing: boolean;
searchParams: any;
currentEventNames: string[];
locationEvents: any;
}

const AttendeeList = (props: IAttendeeList) => {
Expand All @@ -40,6 +41,8 @@ const AttendeeList = (props: IAttendeeList) => {
const location = props.location;
const searchParams = props?.searchParams;
const currentEventNames = props?.currentEventNames;
const locationEvents = props?.locationEvents;
const isAdminInAllEvents = checkAdminInAllEvents(searchParams?.type, locationEvents?.upcomingEvents, locationEvents?.pastEvents);

const defaultTopics = IRL_DEFAULT_TOPICS?.split(',') ?? [];

Expand Down Expand Up @@ -92,8 +95,8 @@ const AttendeeList = (props: IAttendeeList) => {
setPagination({ page: 1, limit: 10 });

const [eventInfo, currentGuestResponse, topics, loggedInUserEvents]: any = await Promise.all([
await getGuestsByLocation(location?.uid, parseSearchParams(searchParams, eventDetails?.events), authToken,currentEventNames),
await getGuestsByLocation(location?.uid, { type: eventType }, authToken,currentEventNames, 1, 1),
await getGuestsByLocation(location?.uid, parseSearchParams(searchParams, eventDetails?.events), authToken, currentEventNames),
await getGuestsByLocation(location?.uid, { type: eventType }, authToken, currentEventNames, 1, 1),
await getTopicsByLocation(location?.uid, eventType),
await getGuestEvents(location?.uid, authToken),
]);
Expand Down Expand Up @@ -150,8 +153,8 @@ const AttendeeList = (props: IAttendeeList) => {
setIsAttendeeLoading(true);
const getEventDetails = async () => {
const authToken = getParsedValue(Cookies.get('authToken'));
const eventInfo: any = await getGuestsByLocation(location?.uid, parseSearchParams(searchParams, eventDetails?.events), authToken,currentEventNames, currentPage, limit);
if (eventInfo.totalGuests>0){
const eventInfo: any = await getGuestsByLocation(location?.uid, parseSearchParams(searchParams, eventDetails?.events), authToken, currentEventNames, currentPage, limit);
if (eventInfo.totalGuests > 0) {
setUpdatedEventDetails((prev) => ({ ...prev, guests: [...prev.guests, ...eventInfo.guests], totalGuests: eventInfo.totalGuests }));
}
setIsAttendeeLoading(false);
Expand Down Expand Up @@ -193,7 +196,7 @@ const AttendeeList = (props: IAttendeeList) => {
)}
<div className="attendeeList">
<div className="attendeeList__toolbar">
<Toolbar location={location} onLogin={onLogin} filteredListLength={updatedEventDetails.totalGuests} eventDetails={updatedEventDetails} userInfo={userInfo} isLoggedIn={isLoggedIn} />
<Toolbar locationEvents={locationEvents} isAdminInAllEvents={isAdminInAllEvents} location={location} onLogin={onLogin} filteredListLength={updatedEventDetails.totalGuests} eventDetails={updatedEventDetails} userInfo={userInfo} isLoggedIn={isLoggedIn} />
</div>
<div className="attendeeList__table">
{/* {eventDetails?.guests?.length > 0 && ( */}
Expand All @@ -211,6 +214,7 @@ const AttendeeList = (props: IAttendeeList) => {
isLoggedIn={isLoggedIn}
onLogin={onLogin}
searchParams={searchParams}
isAdminInAllEvents={isAdminInAllEvents}
/>
{isAttendeeLoading && <TableLoader />}
<div ref={observerRef} className="scroll-observer"></div>
Expand All @@ -223,7 +227,7 @@ const AttendeeList = (props: IAttendeeList) => {
{/* FLOATING BAR */}
{showFloaingBar && (
<div className="irl__floating-bar">
<FloatingBar location={location} eventDetails={updatedEventDetails} selectedGuests={selectedGuests} onClose={onCloseFloatingBar} searchParams={searchParams}/>
<FloatingBar location={location} eventDetails={updatedEventDetails} selectedGuests={selectedGuests} onClose={onCloseFloatingBar} searchParams={searchParams} />
</div>
)}

Expand Down
4 changes: 2 additions & 2 deletions components/page/irl/attendee-list/floating-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ const FloatingBar = (props: IFloatingBar) => {
const onEditGuest = async () => {
if (selectedGuest?.memberUid) {
let guestDetails = await getGuestDetail(selectedGuest?.memberUid, location.uid, authToken, eventType);
guestDetails = transformGuestDetail(guestDetails);

guestDetails = transformGuestDetail(guestDetails, []);
const formData = {
team: {
name: guestDetails?.teamName,
Expand Down
3 changes: 3 additions & 0 deletions components/page/irl/attendee-list/guest-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ interface IGuestList {
isLoggedIn: boolean;
onLogin: () => void;
searchParams: any;
isAdminInAllEvents: any;
}

const GuestList = (props: IGuestList) => {
Expand All @@ -32,6 +33,7 @@ const GuestList = (props: IGuestList) => {
const isLoggedIn = props.isLoggedIn;
const onLogin = props.onLogin;
const searchParams = props?.searchParams;
const isAdminInAllEvents = props?.isAdminInAllEvents;

const analytics = useIrlAnalytics();
const router = useRouter();
Expand Down Expand Up @@ -92,6 +94,7 @@ const GuestList = (props: IGuestList) => {
onchangeSelectionStatus={onchangeSelectionStatus}
isLoggedIn={isLoggedIn}
onLogin={onLogin}
isAdminInAllEvents={isAdminInAllEvents}
/>
</div>
);
Expand Down
5 changes: 4 additions & 1 deletion components/page/irl/attendee-list/guest-table-row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ interface IGuestTableRow {
selectedGuests: string[];
isLoggedIn: boolean;
onLogin: () => void;
isAdminInAllEvents:any;
}

const GuestTableRow = (props: IGuestTableRow) => {
Expand All @@ -32,6 +33,8 @@ const GuestTableRow = (props: IGuestTableRow) => {
const showTelegram = props?.showTelegram;
const onchangeSelectionStatus = props?.onchangeSelectionStatus;
const selectedGuests = props?.selectedGuests;
const isAdminInAllEvents= props?.isAdminInAllEvents;


const guestUid = guest?.memberUid;
const guestName = guest?.memberName ?? '';
Expand Down Expand Up @@ -59,7 +62,7 @@ const GuestTableRow = (props: IGuestTableRow) => {
const remainingTopics = topics?.slice(topicsNeedToShow, topics?.length)?.map((topic: string) => topic);
const atRemovedTelegram = removeAt(getTelegramUsername(telegramId));
const analytics = useIrlAnalytics();
const canUserAddAttendees = (type === 'upcoming' || type === 'past') && canUserPerformEditAction(userInfo?.roles as string[], ALLOWED_ROLES_TO_MANAGE_IRL_EVENTS);
const canUserAddAttendees = isAdminInAllEvents && canUserPerformEditAction(userInfo?.roles as string[], ALLOWED_ROLES_TO_MANAGE_IRL_EVENTS);
const isLoggedIn = props.isLoggedIn;
const onLogin = props.onLogin;

Expand Down
31 changes: 17 additions & 14 deletions components/page/irl/attendee-list/toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ interface IToolbar {
isLoggedIn: boolean;
eventDetails: IGuestDetails;
location: IAnalyticsGuestLocation;
isAdminInAllEvents: any;
locationEvents: any;
}

const Toolbar = (props: IToolbar) => {
Expand All @@ -30,6 +32,10 @@ const Toolbar = (props: IToolbar) => {
const eventDetails = props?.eventDetails;
const updatedUser = eventDetails?.currentGuest ?? null;
const isUserGoing = eventDetails?.isUserGoing;
const isAdminInAllEvents = props?.isAdminInAllEvents;
const locationEvents = props?.locationEvents;
const pastEvents = locationEvents?.pastEvents;
const upcomingEvents = locationEvents?.upcomingEvents;

//states
// const [searchTerm, setSearchTerm] = useState('');
Expand All @@ -39,9 +45,10 @@ const Toolbar = (props: IToolbar) => {
const type = searchParams.get('type');
const search = searchParams.get('search');
const editResponseRef = useRef<HTMLButtonElement>(null);

const router = useRouter();

const inPastEvents = type ? type === 'past' : (pastEvents && pastEvents.length > 0 && upcomingEvents && upcomingEvents.length === 0);

useClickedOutside({
ref: editResponseRef,
callback: () => {
Expand All @@ -51,7 +58,7 @@ const Toolbar = (props: IToolbar) => {

//hooks
const analytics = useIrlAnalytics();
const canUserAddAttendees = (type === 'upcoming' || type === 'past') && canUserPerformEditAction(roles as string[], ALLOWED_ROLES_TO_MANAGE_IRL_EVENTS);
const canUserAddAttendees = isAdminInAllEvents && canUserPerformEditAction(roles as string[], ALLOWED_ROLES_TO_MANAGE_IRL_EVENTS);

const onEditResponseClick = () => {
// setIamGoingPopupProps({isOpen: true, formdata: updatedUser, mode: IAM_GOING_POPUP_MODES.EDIT});
Expand All @@ -60,7 +67,7 @@ const Toolbar = (props: IToolbar) => {

// Open Attendee Details Popup to add guest
const onIAmGoingClick = () => {
document.dispatchEvent(new CustomEvent(EVENTS.OPEN_IAM_GOING_POPUP, { detail: { isOpen: true, formdata: {member: userInfo}, mode: IAM_GOING_POPUP_MODES.ADD} }));
document.dispatchEvent(new CustomEvent(EVENTS.OPEN_IAM_GOING_POPUP, { detail: { isOpen: true, formdata: { member: userInfo }, mode: IAM_GOING_POPUP_MODES.ADD } }));
analytics.trackImGoingBtnClick(location);
};

Expand Down Expand Up @@ -90,11 +97,11 @@ const Toolbar = (props: IToolbar) => {
}
router.push(`${window.location.pathname}?${params.toString()}`, { scroll: false });
analytics.trackGuestListSearch(location, value);
}, 300);
}, 300);

const getValue = (event: React.ChangeEvent<HTMLInputElement>) => {
const searchValue = event?.target?.value;
updateQueryParams(searchValue?.trim())
updateQueryParams(searchValue?.trim());
};

const onLoginClick = () => {
Expand Down Expand Up @@ -146,19 +153,15 @@ const Toolbar = (props: IToolbar) => {
officeHours: updatedUser?.officeHours ?? '',
};

console.log('formData', formData);

document.dispatchEvent(new CustomEvent(EVENTS.OPEN_IAM_GOING_POPUP, { detail: { isOpen: true, formdata: formData, mode: IAM_GOING_POPUP_MODES.EDIT } }));
};


useEffect(() => {
if (searchRef.current) {
searchRef.current.value = search ?? '';
}
}, [router, searchParams]);


return (
<>
<div className="toolbar">
Expand All @@ -177,7 +180,7 @@ const Toolbar = (props: IToolbar) => {
</div>
)}

{!isUserGoing && isUserLoggedIn && type !== 'past' && (
{!isUserGoing && isUserLoggedIn && !inPastEvents && (
<button onClick={onIAmGoingClick} className="mb-btn toolbar__actionCn__imGoingBtn">
I&apos;m Going
</button>
Expand All @@ -194,7 +197,7 @@ const Toolbar = (props: IToolbar) => {
</>
)}

{isUserGoing && isUserLoggedIn && type !== 'past' && (
{isUserGoing && isUserLoggedIn && !inPastEvents && (
<div className="toolbar__actionCn__edit__wrpr">
<button ref={editResponseRef} onClick={onEditResponseClick} className="toolbar__actionCn__edit">
Edit Response
Expand All @@ -213,9 +216,9 @@ const Toolbar = (props: IToolbar) => {
</div>
)}
</div>
<div className="toolbar__search">
<Search searchRef={searchRef} onChange={getValue} placeholder="Search by Attendee, Team or Project" />
</div>
<div className="toolbar__search">
<Search searchRef={searchRef} onChange={getValue} placeholder="Search by Attendee, Team or Project" />
</div>
</div>

<style jsx>
Expand Down
7 changes: 6 additions & 1 deletion components/page/irl/events/irl-events.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,13 @@ const IrlEvents = (props: IIrlEvents) => {
} else if (searchType === 'past') {
return 'past';
}
} else if(eventDetails?.upcomingEvents?.length > 0 && eventDetails?.pastEvents?.length > 0) {
return 'all';
} else if(eventDetails?.upcomingEvents?.length > 0) {
return 'upcoming';
} else if(eventDetails?.pastEvents?.length > 0) {
return 'past';
}
return 'all';
}

let eventType = getEventType(searchType, eventDetails);
Expand Down
1 change: 1 addition & 0 deletions components/page/irl/locations/irl-location.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ const IrlLocation = (props: IrlLocation) => {
else if (hasPastEvents && !hasUpcomingEvents) setPastEvent();
else if (hasUpcomingEvents && hasPastEvents) {
currentParams.delete('type');
currentParams.delete('event');
}
} else if (hasPastEvents && hasUpcomingEvents) {
currentParams.delete('type');
Expand Down
5 changes: 4 additions & 1 deletion components/page/teams/teams-toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,10 @@ const TeamsToolbar = (props: IToolbar) => {
width: 84px;
background-color: #fff;
color: black;
}
.toolbar__left__search-container__searchfrm__input:focus {
outline: none;
}
.toolbar__left__search-container__searchfrm__optns__sbtn {
Expand Down
Loading

0 comments on commit 52864d6

Please sign in to comment.