In the Rekindle Learning Admin Portal 2, we follow a unilateral data flow pattern to maintain clarity and ease of development. This approach ensures that data flows in a single direction, making it easier to trace and manage.
Data flows from the top-level page to its relevant components and then to subcomponents. The global state (sharedState) supplements this flow and is updated as needed.
For instance, consider the Enrollments page:
Enrollments component.EnrollmentDetails.Here is an actual code snippet from the Details tab in Organization Settings:
const DetailsTab: React.FC = () => {
const { sharedState } = useAuthContext();
const selected_organisation = sharedState ? sharedState.selected_organisation : null;
return (
<>
{selected_organisation && (
<>
<DetailsCard {...selected_organisation} />
<CoursesCard {...selected_organisation} />
<GroupTypesCard {...selected_organisation} />
</>
)}
</>
);
};
export default DetailsTab;
In this example, each card within the DetailsTab receives the same state ...selected_organisation.
Within the DetailsCard, various dialogs get the state they need from their parent component:
const DetailsCard = ({
title,
slug,
student_limit,
private_subdomain,
demo_org,
support_email,
apple_app_link,
google_app_link,
huawei_app_link,
id: orgId,
disabled,
}: Organisation) => {
return (
<Styled.Card>
Removed none relevant code for this example...
{/* Dialogs */}
<DisableOrganisationDialog
isOpen={disableOrgDialogOpen}
handleClose={setDisableOrgDialogOpen}
slug={slug}
orgId={orgId}
/>
<EditOrganisationDialog isOpen={editOrgDialogOpen} handleClose={setEditOrgDialogOpen} />
</Styled.Card>
);
};
export default DetailsCard;
Here, each dialog (DisableOrganisationDialog, EditOrganisationDialog) receives the necessary state from the DetailsCard component, this is unilateral inheritance.
To maintain a clean and organized codebase, we adhere to specific directory structures and patterns:
sharedState): Supplemented and updated as needed throughout the data flow.By following these guidelines, you can maintain a clear and efficient data flow and layout in the Rekindle Learning Admin Portal 2, ensuring ease of development and maintenance.