Skip to content

Commit

Permalink
Merge pull request #92 from cabcookie/cabcookie/issue36
Browse files Browse the repository at this point in the history
fix: sections of account details hidden
  • Loading branch information
cabcookie authored May 30, 2024
2 parents 4ed4bd4 + 2bcc584 commit 9a7c684
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 94 deletions.
89 changes: 42 additions & 47 deletions components/accounts/AccountDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,59 +51,54 @@ const AccountDetails: FC<AccountDetailsProps> = ({
<AddControllerDialog account={account} />
<div className="mt-8" />

{accounts &&
accounts.filter(({ controller }) => controller?.id === account.id)
.length > 0 && (
<Accordion type="single" collapsible className="w-full">
<LeanAccordianItem
title="Responsibilities"
isVisible={showResponsibilities}
>
<ResponsibilitiesList
responsibilities={account.responsibilities}
onlyCurrent
/>
<div className="mt-4" />
<ResponsibilitiesDialog
account={account}
<Accordion type="single" collapsible className="w-full">
<LeanAccordianItem
title="Responsibilities"
isVisible={showResponsibilities}
>
<ResponsibilitiesList
responsibilities={account.responsibilities}
onlyCurrent
/>
<div className="mt-4" />
<ResponsibilitiesDialog
account={account}
addResponsibility={addResponsibility}
/>
</LeanAccordianItem>

{accounts && (
<LeanAccordianItem title="Subsidiaries" isVisible={showSubsidaries}>
<Accordion type="single" collapsible className="w-full">
<AccountsList
accounts={accounts}
controllerId={account.id}
addResponsibility={addResponsibility}
/>
</LeanAccordianItem>

<LeanAccordianItem title="Subsidiaries" isVisible={showSubsidaries}>
<Accordion type="single" collapsible className="w-full">
<AccountsList
accounts={accounts}
controllerId={account.id}
addResponsibility={addResponsibility}
/>
</Accordion>
</LeanAccordianItem>
</Accordion>
</LeanAccordianItem>
)}

<LeanAccordianItem
title="Introduction"
isVisible={showIntroduction}
>
<NotesWriter
notes={account.introduction}
placeholder="Describe the account..."
saveNotes={handleUpdateIntroduction}
/>
</LeanAccordianItem>
<LeanAccordianItem title="Introduction" isVisible={showIntroduction}>
<NotesWriter
notes={account.introduction}
placeholder="Describe the account..."
saveNotes={handleUpdateIntroduction}
/>
</LeanAccordianItem>

<LeanAccordianItem title="Projects" isVisible={showProjects}>
<ProjectList accountId={account.id} />
</LeanAccordianItem>
<LeanAccordianItem title="Projects" isVisible={showProjects}>
<ProjectList accountId={account.id} />
</LeanAccordianItem>

<LeanAccordianItem title="Contacts" isVisible={showContacts}>
Test
</LeanAccordianItem>
<LeanAccordianItem title="Contacts" isVisible={showContacts}>
WORK IN PROGRESS
</LeanAccordianItem>

<LeanAccordianItem title="Notes" isVisible={showNotes}>
<AccountNotes accountId={account.id} />
</LeanAccordianItem>
</Accordion>
)}
<LeanAccordianItem title="Notes" isVisible={showNotes}>
<AccountNotes accountId={account.id} />
</LeanAccordianItem>
</Accordion>
</>
);
};
Expand Down
46 changes: 12 additions & 34 deletions components/accounts/AccountsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ const getSortedAccounts = ({
}: GetSortedAccountsProps) =>
accounts
.filter(({ controller, responsibilities }) => {
if (controllerId && controller?.id === controllerId) return true;
if (controllerId && controller && controller.id === controllerId)
return true;
if (controller) return false;
const currentResponsibility =
responsibilities.filter(
({ startDate, endDate }) =>
startDate <= new Date() && (!endDate || endDate >= new Date())
).length > 0;
const currentResponsibility = responsibilities.some(
({ startDate, endDate }) =>
startDate <= new Date() && (!endDate || endDate >= new Date())
);
return (
(showCurrentOnly && currentResponsibility) ||
(showInvalidOnly && !currentResponsibility)
Expand Down Expand Up @@ -112,29 +112,11 @@ const AccountsList: FC<AccountsListProps> = ({
[accounts, controllerId, showCurrentOnly, showInvalidOnly]
);

const updateOrderNumbers =
(newIndex: number) =>
(list: Account[]): Account[] => {
const current = list[newIndex];
if (newIndex === 0) return [{ ...current, order: list[1].order + 1000 }];
if (newIndex === list.length - 1)
return [{ ...current, order: list[newIndex - 1].order - 1000 }];

const orderPrev = list[newIndex - 1].order;
const orderNext = list[newIndex + 1].order;
const orderBetween =
orderPrev > orderNext + 1
? Math.round((orderPrev + orderNext) / 2)
: undefined;
if (orderBetween) return [{ ...current, order: orderBetween }];

return list
.filter((_, index) => index <= newIndex)
.map((account, idx) => ({
...account,
order: orderNext + 1000 * (newIndex - idx + 1),
}));
};
const updateOrderNumbers = (list: Account[]): Account[] =>
list.map((account, idx) => ({
...account,
order: (list.length - idx) * 10,
}));

const moveItem = (items: Account[], oldIndex: number) => (newIndex: number) =>
arrayMove(items, oldIndex, newIndex);
Expand All @@ -145,11 +127,7 @@ const AccountsList: FC<AccountsListProps> = ({
const oldIndex = items.findIndex((item) => item.id === active.id);
const newIndex = items.findIndex((item) => item.id === over.id);

flow(
moveItem(items, oldIndex),
updateOrderNumbers(newIndex),
updateOrder
)(newIndex);
flow(moveItem(items, oldIndex), updateOrderNumbers, updateOrder)(newIndex);
};

return items.length === 0 ? (
Expand Down
15 changes: 2 additions & 13 deletions docs/releases/next.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
# Oberfläche für Accounts implementiert (Version :VERSION)
# Account Ansicht verbessert (Version :VERSION)

In der Account Liste sehe ich nun alle Accounts, für die ich im Moment zuständig bin. Ich kann zusätzlich eine Liste aller Accounts aufklappen, für die ich im Moment nicht zuständig bin.

Ich kann jedem Account ein Mutterunternehmen zuordnen.

Ich kann die Reihenfolge der Accounts nun nach Wichtigkeit ordnen und Zeiträume für Zuständigkeiten definieren.

In der Account-Detailansicht kann ich mir Zuständigkeiten, Tochterunternehmen, eine Einleitung zum Account, aktuelle Projekte und Notizen anschauen.

## Geschlossene Issues

Fixes [#36](https://github.com/cabcookie/personal-crm/issues/36)
Fixes [#33](https://github.com/cabcookie/personal-crm/issues/33)
Bei Accounts, die keine Töchterunternehmen haben, wurden die Details nicht korrekt angezeigt.

0 comments on commit 9a7c684

Please sign in to comment.