Skip to content
Open
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
4 changes: 3 additions & 1 deletion src/pages/persons/person_details/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ const PersonDetails = () => {

const { isAdmin } = useCurrentUser();

const { isNewPerson, isBaptized, male, isConnected } = usePersonDetails();
const { isNewPerson, isBaptized, male, isConnected, personName } =
usePersonDetails();

return (
<Box
Expand All @@ -38,6 +39,7 @@ const PersonDetails = () => {
>
<PageTitle
title={isNewPerson ? t('tr_addNewPerson') : t('tr_editPerson')}
secondaryTitle={isNewPerson ? undefined : personName}
buttons={<PersonButtonActions />}
/>

Expand Down
21 changes: 20 additions & 1 deletion src/pages/persons/person_details/usePersonDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { useAtom, useAtomValue } from 'jotai';
import { personCurrentDetailsState, personsState } from '@states/persons';
import { personSchema } from '@services/dexie/schema';
import { congAccountConnectedState } from '@states/app';
import { fullnameOptionState } from '@states/settings';
import { buildPersonFullname } from '@utils/common';

const usePersonDetails = () => {
const { id } = useParams();
Expand All @@ -15,11 +17,28 @@ const usePersonDetails = () => {

const persons = useAtomValue(personsState);
const isConnected = useAtomValue(congAccountConnectedState);
const fullnameOption = useAtomValue(fullnameOptionState);

const isBaptized = useMemo(() => {
return person.person_data.publisher_baptized.active.value;
}, [person]);

// the shared record may still hold the previously opened person until the
// effect below replaces it, so the title is read from the route instead
const personName = useMemo(() => {
const record = isNewPerson
? person
: persons.find((item) => item.person_uid === id);
Comment on lines +29 to +31

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Edited names leave title stale

When an existing person's name changes, personName reads the saved record instead of current edits. The title retains the old name until saving.

Suggested change
const record = isNewPerson
? person
: persons.find((item) => item.person_uid === id);
const record =
isNewPerson || person.person_uid === id
? person
: persons.find((item) => item.person_uid === id);
Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.


if (!record) return '';

return buildPersonFullname(
record.person_data.person_lastname.value,
record.person_data.person_firstname.value,
fullnameOption
);
}, [id, isNewPerson, person, persons, fullnameOption]);

const male = useMemo(() => {
return person.person_data.male.value;
}, [person]);
Expand All @@ -45,7 +64,7 @@ const usePersonDetails = () => {
}
}, [id, persons, navigate, isNewPerson, setPerson]);

return { isNewPerson, isBaptized, male, isConnected };
return { isNewPerson, isBaptized, male, isConnected, personName };
};

export default usePersonDetails;
Loading