Skip to content

Commit

Permalink
chore(meshconfig): implement EditConfiguration as modal
Browse files Browse the repository at this point in the history
  • Loading branch information
selankon committed Sep 24, 2024
1 parent b5485f1 commit 427b81e
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 75 deletions.
1 change: 1 addition & 0 deletions plugins/lime-plugin-mesh-wide-config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export default {
name: "meshwide/config",
page: MeshConfigPage,
isCommunityProtected: true,
additionalRoutes: [["/meshwide/config", MeshConfigPage]],
} as LimePlugin;
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Trans } from "@lingui/macro";

import {
FullScreenModal,
IFullScreenModalProps,
} from "components/Modal/FullScreenModal";

import {
AddNewSectionBtn,
ConfigSection,
} from "plugins/lime-plugin-mesh-wide-config/src/components/ConfigSection";
import { MeshStatus } from "plugins/lime-plugin-mesh-wide-config/src/components/MeshStatus";
import { useMeshWideConfig } from "plugins/lime-plugin-mesh-wide-config/src/meshConfigQueries";

const EditConfiguration = (props: Partial<IFullScreenModalProps>) => {
const { data: meshWideConfig, isLoading } = useMeshWideConfig({});

return (
<FullScreenModal
title={<Trans>Mesh wide config</Trans>}
isLoading={isLoading}
{...props}
>
{meshWideConfig && (
<>
<div className={"flex flex-col gap-3"}>
{meshWideConfig.map((dropdown, index) => (
<ConfigSection key={index} dropdown={dropdown} />
))}
<AddNewSectionBtn />
</div>
<MeshStatus />
</>
)}
</FullScreenModal>
);
};

export default EditConfiguration;
37 changes: 10 additions & 27 deletions plugins/lime-plugin-mesh-wide-config/src/meshConfigPage.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,19 @@
import { Trans } from "@lingui/macro";
import { useState } from "preact/hooks";
import React from "react";

import { FullScreenModal } from "components/Modal/FullScreenModal";
import { Button } from "components/elements/button";

import {
AddNewSectionBtn,
ConfigSection,
} from "plugins/lime-plugin-mesh-wide-config/src/components/ConfigSection";
import { MeshStatus } from "plugins/lime-plugin-mesh-wide-config/src/components/MeshStatus";
import { useMeshWideConfig } from "plugins/lime-plugin-mesh-wide-config/src/meshConfigQueries";
import EditConfiguration from "plugins/lime-plugin-mesh-wide-config/src/containers/EditConfiguration";

const MeshConfigPage = () => {
const { data: meshWideConfig, isLoading } = useMeshWideConfig({});
// State to show modal
const [showEditConfig, setShowEditConfig] = useState(false);

return (
<FullScreenModal
title={<Trans>Mesh wide config</Trans>}
isLoading={isLoading}
>
{meshWideConfig && (
<>
<div className={"flex flex-col gap-3"}>
{meshWideConfig.map((dropdown, index) => (
<ConfigSection key={index} dropdown={dropdown} />
))}
<AddNewSectionBtn />
</div>
<MeshStatus />
</>
)}
</FullScreenModal>
);
if (showEditConfig) {
return <EditConfiguration onClose={() => setShowEditConfig(false)} />;
}

return <Button onClick={() => setShowEditConfig(true)}>Show modal</Button>;
};

export default MeshConfigPage;
40 changes: 0 additions & 40 deletions plugins/lime-plugin-mesh-wide-config/src/screens/configPage.tsx

This file was deleted.

17 changes: 9 additions & 8 deletions src/components/Modal/FullScreenModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ import { route } from "preact-router";

import Loading from "components/loading";

export interface IFullScreenModalProps {
title: ComponentChildren;
children: ComponentChildren;
isLoading?: boolean;
onClose?: () => void;
}
/**
* Used to show a new view with a close button that return to the backUrl param. Is placed over
* the navbar creating a modal like effect.
Expand All @@ -11,19 +17,14 @@ export const FullScreenModal = ({
title,
children,
isLoading,
backUrl = "/meshwide",
}: {
title: ComponentChildren;
children: ComponentChildren;
isLoading?: boolean;
backUrl?: string;
}) => {
onClose,
}: IFullScreenModalProps) => {
return (
<div className="flex flex-col min-h-screen w-full">
<div className="fixed top-0 left-0 right-0 bg-white z-50 py-7 px-4 flex items-center font-medium">
<div
className={`flex items-center justify-items-start cursor-pointer w-10 h-10 text-black text-3xl`}
onClick={() => route(backUrl)}
onClick={onClose}
>
X
</div>
Expand Down

0 comments on commit 427b81e

Please sign in to comment.