Skip to content

Commit

Permalink
hotfix: dashboard KARRIO API env var references
Browse files Browse the repository at this point in the history
  • Loading branch information
danh91 committed Jul 23, 2024
1 parent b553aac commit b4cd9ec
Show file tree
Hide file tree
Showing 94 changed files with 2,233 additions and 1,355 deletions.
2 changes: 1 addition & 1 deletion apps/api/karrio/server/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2024.6-rc18
2024.6-rc20
19 changes: 14 additions & 5 deletions apps/dashboard/src/context/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { createServerError, isNone, ServerErrorCode, url$ } from "@karrio/lib";
import { getSession } from "next-auth/react";
import {
KARRIO_ADMIN_API_KEY,
KARRIO_PUBLIC_URL,
KARRIO_ADMIN_URL,
KARRIO_URL,
MULTI_TENANT,
Expand Down Expand Up @@ -53,13 +54,21 @@ export const getServerSideProps: GetServerSideProps = async (ctx) => {
}

return {
props: { pathname, orgId, ...metadata, ...subscription, ...data },
props: {
pathname,
orgId,
...metadata,
...subscription,
...data,
},
};
};

export async function loadAPIMetadata(
ctx: RequestContext,
): Promise<{ metadata?: Metadata }> {
export async function loadAPIMetadata(ctx: RequestContext): Promise<{
metadata?: Metadata;
KARRIO_PUBLIC_URL?: string;
MULTI_TENANT?: boolean;
}> {
// Attempt connection to the karrio API to retrieve the API metadata
const API_URL = await getAPIURL(ctx);

Expand All @@ -69,7 +78,7 @@ export async function loadAPIMetadata(

// TODO:: implement version compatibility check here.
await setSessionCookies(ctx as any);
resolve({ metadata });
resolve({ metadata, KARRIO_PUBLIC_URL, MULTI_TENANT });
} catch (e: any | Response) {
logger.error(`Failed to fetch API metadata from (${API_URL})`);
logger.error(e.response?.data || e.response);
Expand Down
8 changes: 5 additions & 3 deletions apps/dashboard/src/context/metadata.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { loadAPIMetadata } from "@/context/main";
import { GetServerSideProps } from "next";


export const getServerSideProps: GetServerSideProps = async (ctx) => {
const { res } = ctx;
const metadata = await loadAPIMetadata(ctx).catch(_ => _);
const metadata = await loadAPIMetadata(ctx).catch((_) => _);

res.setHeader('Cache-Control', 'public, s-maxage=30, stale-while-revalidate=59')
res.setHeader(
"Cache-Control",
"public, s-maxage=30, stale-while-revalidate=59",
);

return { props: { ...metadata } };
};
60 changes: 38 additions & 22 deletions apps/dashboard/src/layouts/section-layout.tsx
Original file line number Diff line number Diff line change
@@ -1,47 +1,63 @@
import { Metadata, SessionType } from '@karrio/types';
import MainLayout from '@/layouts/main-layout';
import { ServerError, p, url$ } from '@karrio/lib';
import Link from 'next/link';
import React from 'react';
import { Metadata, SessionType } from "@karrio/types";
import { ServerError, url$ } from "@karrio/lib";
import MainLayout from "@/layouts/main-layout";
import React from "react";

type SectionLayoutProps = {
metadata?: Metadata,
error?: ServerError,
session?: SessionType,
children?: React.ReactNode,
metadata?: Metadata;
error?: ServerError;
session?: SessionType;
children?: React.ReactNode;
};

export const SectionLayout: React.FC<SectionLayoutProps> = ({ metadata, error, children }) => {
export const SectionLayout: React.FC<SectionLayoutProps> = ({
metadata,
error,
children,
}) => {
console.log("metadata", metadata);
return (
<MainLayout error={error}>
<section className="hero is-fullheight">

<div className="container">
<div className="has-text-centered my-6 pt-5">
<a href={url$`${metadata?.APP_WEBSITE}`} className="is-size-4 has-text-primary has-text-weight-bold">
<a
href={url$`${metadata?.APP_WEBSITE}`}
className="is-size-4 has-text-primary has-text-weight-bold"
>
{metadata?.APP_NAME}
</a>
</div>

{children}

</div>

<div className="hero-footer">
<div className="content has-text-centered">
<p>
{metadata?.APP_NAME.includes("Karrio") && <>
<a href="https://karrio.io" className="button is-white" target="_blank" rel="noreferrer">
<span>&copy; {metadata?.APP_NAME}</span>
</a>
<a href="https://docs.karrio.io" className="button is-white" target="_blank" rel="noreferrer">
<span>Documentation</span>
</a>
</>}
{metadata?.APP_NAME.includes("Karrio") && (
<>
<a
href="https://karrio.io"
className="button is-white"
target="_blank"
rel="noreferrer"
>
<span>&copy; {metadata?.APP_NAME}</span>
</a>
<a
href="https://docs.karrio.io"
className="button is-white"
target="_blank"
rel="noreferrer"
>
<span>Documentation</span>
</a>
</>
)}
</p>
</div>
</div>

</section>
</MainLayout>
);
Expand Down
Loading

0 comments on commit b4cd9ec

Please sign in to comment.