Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dashboard): welcome banner not closing for pocket user #3189

Merged
merged 7 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/definition/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export type SessionResponseType = {
os: string;
isMobile: boolean;
};
last_seen: number;
last_seen: string;
};

export type CongregationCreateResponseType = {
Expand Down Expand Up @@ -241,6 +241,7 @@ export type CongregationUserType = {
user_local_uid: string;
user_members_delegate: string[];
pocket_invitation_code?: string;
createdAt?: string;
};
sessions?: SessionResponseType[];
};
Expand Down
1 change: 1 addition & 0 deletions src/features/app_start/pocket/signup/useSignup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ const useSignup = () => {
'cong_settings.cong_circuit': app_settings.cong_settings.cong_circuit,
'cong_settings.midweek_meeting': midweekMeeting,
'cong_settings.weekend_meeting': weekendMeeting,
'cong_settings.cong_new': false,
});

await handleLoadApp();
Expand Down
1 change: 1 addition & 0 deletions src/features/app_start/vip/startup/useStartup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ const useStartup = () => {

if (
isAuthenticated &&
congName.length === 0 &&
(remoteMasterKey.length === 0 || remoteAccessCode.length === 0)
) {
setCongID(result.cong_id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { schedulesState } from '@states/schedules';
import { sourcesState } from '@states/sources';
import { speakersCongregationsActiveState } from '@states/speakers_congregations';
import { visitingSpeakersActiveState } from '@states/visiting_speakers';
import { assignmentState } from '@states/assignment';
import { weekTypeState } from '@states/weekType';

const useExport = () => {
const persons = useRecoilValue(personsState);
Expand All @@ -27,6 +29,8 @@ const useExport = () => {
const schedules = useRecoilValue(schedulesState);
const sources = useRecoilValue(sourcesState);
const visitingSpeakers = useRecoilValue(visitingSpeakersActiveState);
const assignments = useRecoilValue(assignmentState);
const weekTypes = useRecoilValue(weekTypeState);
const speakersCongregations = useRecoilValue(
speakersCongregationsActiveState
);
Expand All @@ -48,6 +52,28 @@ const useExport = () => {
return app_settings;
};

const handleGetAssignments = () => {
const assignmentsList = assignments.map((record) => {
return {
code: record.code,
assignment_type_name: record.assignment_type_name.E,
};
rhahao marked this conversation as resolved.
Show resolved Hide resolved
});

return assignmentsList;
};

const handleGetWeekTypes = () => {
const weekTypesList = weekTypes.map((record) => {
return {
id: record.id,
week_type_name: record.week_type_name.EN,
};
});

return weekTypesList;
};

const handleDownload = async () => {
if (isProcessing) return;

Expand All @@ -59,6 +85,7 @@ const useExport = () => {
exported: new Date().toISOString(),
version: import.meta.env.PACKAGE_VERSION,
data: {
assignments: handleGetAssignments(),
app_settings: handleGetSettings(),
branch_cong_analysis: branchCongAnalysis,
branch_field_service_reports: branchFieldReports,
Expand All @@ -70,10 +97,11 @@ const useExport = () => {
sources,
speakers_congregations: speakersCongregations,
visiting_speakers: visitingSpeakers,
week_type: handleGetWeekTypes(),
},
};

const prettyJsonData = JSON.stringify(backupData, null, 2);
const prettyJsonData = JSON.stringify(backupData);

const blob = new Blob([prettyJsonData], { type: 'application/json' });

Expand Down
4 changes: 2 additions & 2 deletions src/features/demo/start/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import useStart from './useStart';
import AppLoading from '@components/loading';
import Typography from '@components/typography';

const DemoStatup = () => {
const DemoStartup = () => {
const { t } = useAppTranslation();

useStart();
Expand Down Expand Up @@ -42,4 +42,4 @@ const DemoStatup = () => {
);
};

export default DemoStatup;
export default DemoStartup;
69 changes: 0 additions & 69 deletions src/features/index.ts

This file was deleted.

39 changes: 14 additions & 25 deletions src/features/persons/app_user_profile/index.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import { Box } from '@mui/material';
import usePersonAppPersonProfile from './useAppUserProfile';
import Typography from '@components/typography';
import { IconAddPerson, IconArrowLink } from '@components/icons';
import { useAppTranslation } from '@hooks/index';
import useAppUserProfile from './useAppUserProfile';
import Button from '@components/button';
import { IconAddPerson, IconArrowLink } from '@components/icons';
import Typography from '@components/typography';
import Markup from '@components/text_markup';

const PersonAppUserProfile = () => {
const { t } = useAppTranslation();
const {
userIsRegistered,
getTextForAppPersonProfileDesc,
navigateToManageAccess,
} = usePersonAppPersonProfile();

const { navigateToManageAccess, userDescription, user } = useAppUserProfile();

return (
<Box
Expand All @@ -21,10 +19,8 @@ const PersonAppUserProfile = () => {
display: 'flex',
flexDirection: 'column',
borderRadius: 'var(--radius-xl)',
backgroundColor: userIsRegistered
? 'var(--white)'
: 'var(--accent-150)',
border: `1px ${userIsRegistered ? 'solid' : 'dashed'} var(--accent-300)`,
backgroundColor: user ? 'var(--white)' : 'var(--accent-150)',
border: `1px ${user ? 'solid' : 'dashed'} var(--accent-300)`,
}}
>
<Box
Expand All @@ -34,24 +30,17 @@ const PersonAppUserProfile = () => {
flexDirection: 'column',
}}
>
<Typography className="h2" color="var(--black)">
{t('tr_appUserProfile')}
</Typography>
<Typography
className="body-regular"
color="var(--black)"
dangerouslySetInnerHTML={{ __html: getTextForAppPersonProfileDesc() }}
></Typography>
<Typography className="h2">{t('tr_appUserProfile')}</Typography>

<Markup className="body-regular" content={userDescription} />
</Box>
<Button
startIcon={userIsRegistered ? <IconArrowLink /> : <IconAddPerson />}
startIcon={user ? <IconArrowLink /> : <IconAddPerson />}
variant="small"
sx={{ width: 'fit-content' }}
sx={{ width: 'fit-content', height: '32px', minHeight: '32px' }}
onClick={() => navigateToManageAccess()}
>
{userIsRegistered
? t('tr_manageUserProfileSettings')
: t('tr_createUserProfile')}
{user ? t('tr_manageUserProfileSettings') : t('tr_createUserProfile')}
</Button>
</Box>
);
Expand Down
76 changes: 40 additions & 36 deletions src/features/persons/app_user_profile/useAppUserProfile.tsx
Original file line number Diff line number Diff line change
@@ -1,62 +1,66 @@
import { CongregationUserType } from '@definition/api';
import { useMemo } from 'react';
import { useNavigate } from 'react-router-dom';
import { useRecoilValue } from 'recoil';
import { useAppTranslation } from '@hooks/index';
import { formatDate } from '@services/dateformat';
import { congregationsPersonsState } from '@states/app';
import { congregationUsersState } from '@states/app';
import { personCurrentDetailsState } from '@states/persons';
import { shortDateFormatState } from '@states/settings';
import { useNavigate } from 'react-router-dom';
import { useRecoilValue } from 'recoil';

const usePersonAppPersonProfile = () => {
const useAppUserProfile = () => {
const navigate = useNavigate();

const { t } = useAppTranslation();
const congregationsPersons = useRecoilValue(congregationsPersonsState);

const congregationsUsers = useRecoilValue(congregationUsersState);
const currentPersonDetails = useRecoilValue(personCurrentDetailsState);
const shortDateFormat = useRecoilValue(shortDateFormatState);
const navigate = useNavigate();

const userIsRegistered: boolean = congregationsPersons.some(
(person) =>
person.profile.user_local_uid === currentPersonDetails.person_uid
);

const currentPersonInCongragation: CongregationUserType =
congregationsPersons.find(
const user = useMemo(() => {
return congregationsUsers.find(
(person) =>
person.profile.user_local_uid === currentPersonDetails.person_uid
);
}, [congregationsUsers, currentPersonDetails]);

const last_seen = useMemo(() => {
if (!user) return;

if (!user.sessions) return;

if (user.sessions.length === 0) return;

const getTextForAppPersonProfileDesc = () => {
if (userIsRegistered) {
const lastTimeOnline = currentPersonInCongragation.sessions[0]?.last_seen;
const last = user.sessions
.toSorted((a, b) => b.last_seen.localeCompare(a.last_seen))
.at(0);
rhahao marked this conversation as resolved.
Show resolved Hide resolved

const formattedLastTimeOnline = lastTimeOnline
? formatDate(new Date(lastTimeOnline), shortDateFormat)
: t('tr_notYet');
return last.last_seen;
}, [user]);

return t('tr_appUserProfileRegisteredDesc', {
lastTimeOnline: formattedLastTimeOnline,
});
const userDescription = useMemo(() => {
if (!user) {
return t('tr_appUserProfileNotRegisteredDesc');
}

return t('tr_appUserProfileNotRegisteredDesc');
};
const createdFormatted = last_seen
? formatDate(new Date(last_seen), shortDateFormat)
: t('tr_notYet');

return t('tr_appUserProfileRegisteredDesc', {
lastTimeOnline: createdFormatted,
});
}, [user, t, shortDateFormat, last_seen]);

const navigateToManageAccess = () => {
if (userIsRegistered) {
navigate(`/manage-access/${currentPersonInCongragation.id}`);
if (user) {
navigate(`/manage-access/${user.id}`);
return;
}

navigate(`/manage-access/`);
return;
navigate(`/manage-access`);
};

return {
userIsRegistered,
currentPersonInCongragation,
getTextForAppPersonProfileDesc,
navigateToManageAccess,
};
return { user, userDescription, navigateToManageAccess };
};

export default usePersonAppPersonProfile;
export default useAppUserProfile;
4 changes: 2 additions & 2 deletions src/features/persons/enrollments/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Button from '@components/button';
import EnrollmentItem from './enrollment_item';
import Typography from '@components/typography';

const Enrollments = () => {
const PersonEnrollments = () => {
const { t } = useAppTranslation();

const { isPersonEditor } = useCurrentUser();
Expand Down Expand Up @@ -74,4 +74,4 @@ const Enrollments = () => {
);
};

export default Enrollments;
export default PersonEnrollments;
4 changes: 2 additions & 2 deletions src/features/persons/privileges/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Button from '@components/button';
import Typography from '@components/typography';
import PrivilegeItem from './privilege_item';

const Privileges = () => {
const PersonPrivileges = () => {
const { t } = useAppTranslation();

const { isPersonEditor } = useCurrentUser();
Expand Down Expand Up @@ -76,4 +76,4 @@ const Privileges = () => {
);
};

export default Privileges;
export default PersonPrivileges;
Loading
Loading