Skip to content

Commit

Permalink
fix: redirection issues and instance validation changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sriramveeraghanta committed May 10, 2024
1 parent 0ad8bf7 commit 2ef3c06
Show file tree
Hide file tree
Showing 14 changed files with 170 additions and 54 deletions.
7 changes: 3 additions & 4 deletions admin/components/admin-sidebar/help-section.tsx
Expand Up @@ -7,9 +7,10 @@ import { Transition } from "@headlessui/react";
import { ExternalLink, FileText, HelpCircle, MoveLeft } from "lucide-react";
import { DiscordIcon, GithubIcon, Tooltip } from "@plane/ui";
// hooks
import { useInstance, useTheme } from "@/hooks/store";
import { useTheme } from "@/hooks/store";
// assets
import packageJson from "package.json";
import { WEB_BASE_URL } from "@/helpers/common.helper";

const helpOptions = [
{
Expand All @@ -30,16 +31,14 @@ const helpOptions = [
];

export const HelpSection: FC = observer(() => {
// hooks
const { instance } = useInstance();
// states
const [isNeedHelpOpen, setIsNeedHelpOpen] = useState(false);
// store
const { isSidebarCollapsed, toggleSidebar } = useTheme();
// refs
const helpOptionsRef = useRef<HTMLDivElement | null>(null);

const redirectionLink = `${instance?.config?.app_base_url ? `${instance?.config?.app_base_url}/create-workspace` : `/god-mode/`}`;
const redirectionLink = encodeURI(WEB_BASE_URL + "/create-workspace");

return (
<div
Expand Down
2 changes: 2 additions & 0 deletions apiserver/plane/license/api/views/instance.py
Expand Up @@ -38,6 +38,8 @@ def get_permissions(self):
@cache_response(60 * 60 * 2, user=False)
def get(self, request):
instance = Instance.objects.first()

print("Instance: ", instance)
# get the instance
if instance is None:
return Response(
Expand Down
13 changes: 0 additions & 13 deletions apiserver/plane/settings/local.py
Expand Up @@ -30,19 +30,6 @@
MEDIA_URL = "/uploads/"
MEDIA_ROOT = os.path.join(BASE_DIR, "uploads") # noqa

CORS_ALLOWED_ORIGINS = [
"http://localhost",
"http://127.0.0.1",
"http://localhost:3000",
"http://127.0.0.1:3000",
"http://localhost:3001",
"http://127.0.0.1:3001",
"http://localhost:3002",
"http://127.0.0.1:3002",
]
CSRF_TRUSTED_ORIGINS = CORS_ALLOWED_ORIGINS
CORS_ALLOW_ALL_ORIGINS = True

LOG_DIR = os.path.join(BASE_DIR, "logs") # noqa

if not os.path.exists(LOG_DIR):
Expand Down
9 changes: 9 additions & 0 deletions apiserver/plane/space/views/base.py
Expand Up @@ -21,6 +21,7 @@
# Module imports
from plane.utils.exception_logger import log_exception
from plane.utils.paginator import BasePaginator
from plane.authentication.session import BaseSessionAuthentication


class TimezoneMixin:
Expand Down Expand Up @@ -49,6 +50,10 @@ class BaseViewSet(TimezoneMixin, ModelViewSet, BasePaginator):
SearchFilter,
)

authentication_classes = [
BaseSessionAuthentication,
]

filterset_fields = []

search_fields = []
Expand Down Expand Up @@ -146,6 +151,10 @@ class BaseAPIView(TimezoneMixin, APIView, BasePaginator):

search_fields = []

authentication_classes = [
BaseSessionAuthentication,
]

def filter_queryset(self, queryset):
for backend in list(self.filter_backends):
queryset = backend().filter_queryset(self.request, queryset, self)
Expand Down
3 changes: 2 additions & 1 deletion space/components/instance/index.ts
@@ -1 +1,2 @@
export * from "./not-ready-view";
export * from "./not-ready-view";
export * from "./instance-failure-view";
38 changes: 38 additions & 0 deletions space/components/instance/instance-failure-view.tsx
@@ -0,0 +1,38 @@
import { FC } from "react";
import Image from "next/image";
import { useTheme } from "next-themes";
import { Button } from "@plane/ui";
// assets
import InstanceFailureDarkImage from "public/instance/instance-failure-dark.svg";
import InstanceFailureImage from "public/instance/instance-failure.svg";

type InstanceFailureViewProps = {
mutate: () => void;
};

export const InstanceFailureView: FC<InstanceFailureViewProps> = (props) => {
const { mutate } = props;
const { resolvedTheme } = useTheme();

const instanceImage = resolvedTheme === "dark" ? InstanceFailureDarkImage : InstanceFailureImage;

return (
<div className="h-full w-full relative container px-5 mx-auto flex justify-center items-center mt-10">
<div className="w-auto max-w-2xl relative space-y-8 py-10">
<div className="relative flex flex-col justify-center items-center space-y-4">
<Image src={instanceImage} alt="Plane Logo" />
<h3 className="font-medium text-2xl text-white ">Unable to fetch instance details.</h3>
<p className="font-medium text-base text-center">
We were unable to fetch the details of the instance. <br />
Fret not, it might just be a connectivity issue.
</p>
</div>
<div className="flex justify-center">
<Button size="md" onClick={mutate}>
Retry
</Button>
</div>
</div>
</div>
);
};
51 changes: 22 additions & 29 deletions space/components/instance/not-ready-view.tsx
@@ -1,40 +1,33 @@
import { FC } from "react";
import Image from "next/image";
import { useTheme } from "next-themes";
// icons
import { UserCog2 } from "lucide-react";
import Link from "next/link";
// ui
import { getButtonStyling } from "@plane/ui";
import { Button } from "@plane/ui";
// helpers
import { ADMIN_BASE_URL, ADMIN_BASE_PATH } from "@/helpers/common.helper";
// images
import instanceNotReady from "public/instance/plane-instance-not-ready.webp";
import PlaneBlackLogo from "public/plane-logos/black-horizontal-with-blue-logo.svg";
import PlaneWhiteLogo from "public/plane-logos/white-horizontal-with-blue-logo.svg";
import PlaneTakeOffImage from "@/public/instance/plane-takeoff.png";

export const InstanceNotReady: FC = () => {
const { resolvedTheme } = useTheme();

const planeLogo = resolvedTheme === "dark" ? PlaneWhiteLogo : PlaneBlackLogo;
const GOD_MODE_URL = encodeURI(ADMIN_BASE_URL + ADMIN_BASE_PATH + "/setup/?auth_enabled=0");

return (
<div className="h-screen w-full overflow-y-auto bg-onboarding-gradient-100">
<div className="h-full w-full pt-24">
<div className="mx-auto h-full rounded-t-md border-x border-t border-custom-border-100 bg-onboarding-gradient-100 px-4 pt-4 shadow-sm sm:w-4/5 md:w-2/3">
<div className="relative h-full rounded-t-md bg-onboarding-gradient-200 px-7 sm:px-0">
<div className="flex items-center justify-center py-10">
<Image src={planeLogo} className="h-[44px] w-full" alt="Plane logo" />
</div>
<div className="mt-20">
<Image src={instanceNotReady} className="w-full" alt="Instance not ready" />
</div>
<div className="flex w-full flex-col items-center gap-5 py-12 pb-20">
<h3 className="text-2xl font-medium">Your Plane instance isn{"'"}t ready yet</h3>
<p className="text-sm">Ask your Instance Admin to complete set-up first.</p>
<a href="/god-mode" className={`${getButtonStyling("primary", "md")} mt-4`}>
<UserCog2 className="h-3.5 w-3.5" />
Get started
</a>
</div>
</div>
<div className="h-full w-full relative container px-5 mx-auto flex justify-center items-center mt-10">
<div className="w-auto max-w-2xl relative space-y-8 py-10">
<div className="relative flex flex-col justify-center items-center space-y-4">
<h1 className="text-3xl font-bold pb-3">Welcome aboard Plane!</h1>
<Image src={PlaneTakeOffImage} alt="Plane Logo" />
<p className="font-medium text-base text-onboarding-text-400">
Get started by setting up your instance and workspace
</p>
</div>

<div>
<Link href={GOD_MODE_URL}>
<Button size="lg" className="w-full">
Get started
</Button>
</Link>
</div>
</div>
</div>
Expand Down
3 changes: 3 additions & 0 deletions space/helpers/common.helper.ts
Expand Up @@ -3,6 +3,9 @@ import { twMerge } from "tailwind-merge";

export const API_BASE_URL = process.env.NEXT_PUBLIC_API_BASE_URL || "";

export const ADMIN_BASE_URL = process.env.NEXT_PUBLIC_ADMIN_BASE_URL || "";
export const ADMIN_BASE_PATH = process.env.NEXT_PUBLIC_ADMIN_BASE_PATH || "";

export const SPACE_BASE_PATH = process.env.NEXT_PUBLIC_SPACE_BASE_PATH || "";

export const WEB_BASE_URL = process.env.NEXT_PUBLIC_WEB_BASE_URL || "";
Expand Down
8 changes: 3 additions & 5 deletions space/layouts/project-layout.tsx
@@ -1,18 +1,16 @@
import Image from "next/image";

// mobx
import { observer } from "mobx-react-lite";
import planeLogo from "public/plane-logo.svg";
import Image from "next/image";
// components
import IssueNavbar from "@/components/issues/navbar";
// logo
import planeLogo from "public/plane-logo.svg";

const ProjectLayout = ({ children }: { children: React.ReactNode }) => (
<div className="relative flex h-screen min-h-[500px] w-screen flex-col overflow-hidden">
<div className="relative flex h-[60px] flex-shrink-0 select-none items-center border-b border-custom-border-300 bg-custom-sidebar-background-100">
<IssueNavbar />
</div>
<div className="relative h-full w-full overflow-hidden bg-custom-background-90">{children}</div>

<a
href="https://plane.so"
className="fixed bottom-2.5 right-5 !z-[999999] flex items-center gap-1 rounded border border-custom-border-200 bg-custom-background-100 px-2 py-1 shadow-custom-shadow-2xs"
Expand Down
1 change: 1 addition & 0 deletions space/lib/wrappers/auth-wrapper.tsx
Expand Up @@ -32,6 +32,7 @@ export const AuthWrapper: FC<TAuthWrapper> = observer((props) => {
<Spinner />
</div>
);

if (pageType === EPageTypes.PUBLIC) return <>{children}</>;

if (pageType === EPageTypes.INIT) {
Expand Down
9 changes: 7 additions & 2 deletions space/lib/wrappers/instance-wrapper.tsx
Expand Up @@ -4,7 +4,7 @@ import useSWR from "swr";
// ui
import { Spinner } from "@plane/ui";
// components
import { InstanceNotReady } from "@/components/instance";
import { InstanceNotReady, InstanceFailureView } from "@/components/instance";
// hooks
import { useInstance } from "@/hooks/store";

Expand All @@ -17,8 +17,11 @@ export const InstanceWrapper: FC<TInstanceWrapper> = observer((props) => {
// hooks
const { isLoading, instance, fetchInstanceInfo } = useInstance();

const { isLoading: isSWRLoading } = useSWR("INSTANCE_INFORMATION", () => fetchInstanceInfo(), {
const { isLoading: isSWRLoading, mutate } = useSWR("INSTANCE_INFORMATION", () => fetchInstanceInfo(), {
revalidateOnFocus: false,
revalidateIfStale: false,
revalidateOnReconnect: false,
errorRetryCount: 0,
});

if (isSWRLoading || isLoading)
Expand All @@ -28,6 +31,8 @@ export const InstanceWrapper: FC<TInstanceWrapper> = observer((props) => {
</div>
);

if (!instance) return <InstanceFailureView mutate={mutate} />;

if (instance?.instance?.is_setup_done === false) return <InstanceNotReady />;

return <>{children}</>;
Expand Down
40 changes: 40 additions & 0 deletions space/public/instance/instance-failure-dark.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 40 additions & 0 deletions space/public/instance/instance-failure.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added space/public/instance/plane-takeoff.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2ef3c06

Please sign in to comment.