Skip to content

Commit

Permalink
Merge pull request #445 from karrioapi/karrio-admin
Browse files Browse the repository at this point in the history
[feat] karrio admin
  • Loading branch information
danh91 authored Dec 11, 2023
2 parents fd48f02 + 6379726 commit 07561a6
Show file tree
Hide file tree
Showing 161 changed files with 35,016 additions and 1,344 deletions.
2 changes: 1 addition & 1 deletion apps/api/karrio/server/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2023.9.3
2023.9.4
16 changes: 13 additions & 3 deletions apps/api/karrio/server/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@
"module": "karrio.server.core",
"urls": "karrio.server.core.urls",
},
{
"app": "karrio.server.iam",
"module": "karrio.server.iam",
},
{
"app": "karrio.server.providers",
"module": "karrio.server.providers",
Expand Down Expand Up @@ -127,8 +131,14 @@
"module": "karrio.server.admin",
"urls": "karrio.server.admin.urls",
},
{"app": "karrio.server.pricing", "module": "karrio.server.pricing"},
{"app": "karrio.server.apps", "module": "karrio.server.apps"},
{
"app": "karrio.server.pricing",
"module": "karrio.server.pricing",
},
{
"app": "karrio.server.apps",
"module": "karrio.server.apps",
},
]
if importlib.util.find_spec(app["module"]) is not None # type:ignore
]
Expand Down Expand Up @@ -430,7 +440,7 @@
),
"ROTATE_REFRESH_TOKENS": False,
"BLACKLIST_AFTER_ROTATION": False,
"UPDATE_LAST_LOGIN": False,
"UPDATE_LAST_LOGIN": True,
"ALGORITHM": "HS256",
"SIGNING_KEY": SECRET_KEY,
"VERIFYING_KEY": None,
Expand Down
2 changes: 1 addition & 1 deletion apps/api/karrio/server/settings/constance.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
),
"TRACKER_DATA_RETENTION": (
TRACKER_DATA_RETENTION,
"Order data retention period (in days)",
"Trackers data retention period (in days)",
int,
),
"SHIPMENT_DATA_RETENTION": (
Expand Down
1 change: 1 addition & 0 deletions apps/dashboard/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const moduleExports = {
MULTI_TENANT: MULTI_TENANT,
KARRIO_PUBLIC_URL: KARRIO_PUBLIC_URL,
NEXTAUTH_URL: process.env.DASHBOARD_URL,
DASHBOARD_URL: process.env.DASHBOARD_URL,
DASHBOARD_VERSION: process.env.DASHBOARD_VERSION,
},
sentry: {
Expand Down
9 changes: 8 additions & 1 deletion apps/dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,30 @@
"@uiw/react-codemirror": "^4.19.4",
"axios": "^0.25.0",
"bulma": "^0.9.4",
"core-js": "^3.34.0",
"graphiql": "^3.0.10",
"graphql": "^16.8.1",
"graphql-tag": "^2.12.6",
"graphql-ws": "^5.14.2",
"highlight.js": "^11.2.0",
"js-beautify": "^1.14.7",
"libphonenumber-js": "^1.9.23",
"lodash.groupby": "^4.6.0",
"lodash.isequal": "^4.5.0",
"lodash.snakecase": "^4.1.1",
"lodash.tonumber": "^4.0.3",
"mobx": "^6.12.0",
"moment": "^2.29.4",
"next": "^13.4.20-canary.13",
"next-auth": "^4.24.5",
"pino": "^7.0.3",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"redoc": "^2.1.3",
"request-ip": "^3.3.0",
"rxjs": "^7.3.0",
"sass": "^1.37.5"
"sass": "^1.37.5",
"styled-components": "^6.1.1"
},
"devDependencies": {
"@types/node": "20.10.0",
Expand Down
19 changes: 19 additions & 0 deletions apps/dashboard/src/context/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ export const getServerSideProps: GetServerSideProps = async (ctx) => {
}
}

if (needStaffAccess(pathname, data)) {
return {
redirect: {
permanent: false,
destination: '/'
}
}
}

return {
props: { pathname, orgId, ...metadata, ...subscription, ...data }
};
Expand Down Expand Up @@ -197,6 +206,14 @@ function needValidSubscription({ subscription }: { subscription?: SubscriptionTy
)
}

function needStaffAccess(pathname, { user }: { user?: any | null }) {
return (
pathname.includes('/admin') &&
!!user &&
user?.is_staff === false
)
}

async function getAPIURL(ctx: RequestContext) {
if (!publicRuntimeConfig?.MULTI_TENANT) {
return KARRIO_API;
Expand Down Expand Up @@ -226,8 +243,10 @@ const USER_DATA_QUERY = `{
email
full_name
is_staff
is_superuser
last_login
date_joined
permissions
}
}`;
const ORG_DATA_QUERY = `{
Expand Down
58 changes: 58 additions & 0 deletions apps/dashboard/src/layouts/admin-layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { ModeIndicator } from '@karrio/ui/components/mode-indicator';
import { AdminSidebar } from '@karrio/ui/components/admin-sidebar';
import { AdminNavbar } from '@karrio/ui/components/admin-navbar';
import { Notifier } from '@karrio/ui/components/notifier';
import { AppLink } from '@karrio/ui/components/app-link';
import React from 'react';


export const AdminLayout: React.FC<{ showModeIndicator?: boolean, children?: React.ReactNode }> = ({ children, ...props }) => {
return (
<>

<div className="is-flex is-flex-direction-column" style={{ minHeight: '100vh' }}>
{props.showModeIndicator && <ModeIndicator />}

<Notifier />
<AdminNavbar />

<div className="is-flex is-flex-grow-1" style={{ paddingTop: 0, height: '100%' }}>
<div className="modal-background"></div>
<div className="modal-card admin-modal" style={{ width: '100%' }}>

<section className="modal-card-body modal-form p-0 pt-5">
<header className="form-floating-header p-2 is-flex is-justify-content-space-between">
<span className="icon-text has-text-weight-bold is-size-6">
<span className="icon">
<i className="fas fa-tools"></i>
</span>
<span>Administration</span>
</span>
<div>
<AppLink href="/" className="button is-small is-white" shallow={false} prefetch={false}>
<span className="icon is-size-6">
<i className="fa fa-times"></i>
</span>
</AppLink>
</div>
</header>

<div className="admin-wrapper is-relative mt-6 p-0">

<AdminSidebar />

<div className="plex-wrapper" style={{ background: 'inherit', marginLeft: '260px', minHeight: '70vh' }}>
{children}
</div>

</div>

</section>

</div>
</div>

</div>
</>
)
};
13 changes: 6 additions & 7 deletions apps/dashboard/src/layouts/dashboard-layout.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
import { ExpandedSidebar } from '@karrio/ui/components/expanded-sidebar';
import { ModeIndicator } from '@karrio/ui/components/mode-indicator';
import { Notifier } from '@karrio/ui/components/notifier';
import { Navbar } from '@karrio/ui/components/navbar';
import { Footer } from '@karrio/ui/components/footer';
import React from 'react';


export const DashboardLayout: React.FC<{ showModeIndicator?: boolean, children?: React.ReactNode }> = ({ children, ...props }) => {
return (
<>
{props.showModeIndicator && <ModeIndicator />}
<ExpandedSidebar />

<div className="plex-wrapper is-flex is-flex-direction-column">
<div className="wrapper-inner is-flex-grow-1 mb-3">
<div className="plex-wrapper is-flex is-flex-direction-column pb-0">
<div className="wrapper-inner is-flex-grow-1 pb-0">
<Notifier />
<Navbar showModeIndicator={props.showModeIndicator} />
<Navbar />

<div className="dashboard-content is-relative" style={{ paddingTop: 0, height: '100%' }}>
<div className="dashboard-content is-relative pt-0 pb-4" style={{ minHeight: "93vh" }}>
{children}
</div>

</div>

<Footer />
</div>

</>
Expand Down
20 changes: 20 additions & 0 deletions apps/dashboard/src/layouts/embed-layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { ExpandedSidebar } from '@karrio/ui/components/expanded-sidebar';
import { ModeIndicator } from '@karrio/ui/components/mode-indicator';
import React from 'react';


export const EmbedLayout: React.FC<{ showModeIndicator?: boolean, children?: React.ReactNode }> = ({ children, ...props }) => {
return (
<>
{props.showModeIndicator && <ModeIndicator />}
<ExpandedSidebar />

<div className="plex-wrapper is-relative p-0">

{children}

</div>

</>
)
};
30 changes: 30 additions & 0 deletions apps/dashboard/src/modules/Admin/carrier_connections.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { AuthenticatedPage } from "@/layouts/authenticated-page";
import { AdminLayout } from "@/layouts/admin-layout";
import Head from "next/head";

export { getServerSideProps } from "@/context/main";


export default function Page(pageProps: any) {
const { APP_NAME } = (pageProps as any).metadata || {};

const Component: React.FC = () => {

return (
<>
<header className="px-0 pb-5 pt-1 mb-1">
<span className="title is-4 has-text-weight-bold">Carrier connections</span>
</header>
</>
);
};

return AuthenticatedPage((
<AdminLayout showModeIndicator={true}>
<Head><title>{`Carriers - ${APP_NAME}`}</title></Head>

<Component />

</AdminLayout>
), pageProps)
}
Loading

0 comments on commit 07561a6

Please sign in to comment.