Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix env variables issue #157

Merged
merged 3 commits into from
Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FC, useState, useEffect, useCallback } from "react";
import { FC, useState, useEffect, useCallback, useMemo } from "react";
import {
BasicProgressMessageBox,
ProgressMessageBoxState,
Expand All @@ -18,6 +18,7 @@ import { sendAmplitudeData } from "@/lib/amplitude";
import { AxiosError } from "axios";
import { ErrorDetails } from "@/lib/instill/types";
import OutlineButton from "@/components/ui/Buttons/OutlineButton";
import useDeleteResourceGuard from "@/hooks/useDeleteResourceGuard";

export type ConfigureDestinationFormProps = {
destination: Nullable<DestinationWithDefinition>;
Expand Down Expand Up @@ -104,6 +105,8 @@ const ConfigureDestinationForm: FC<ConfigureDestinationFormProps> = ({
// # #
// ###################################################################

const { disableResourceDeletion } = useDeleteResourceGuard();

const [deleteDestinationModalIsOpen, setDeleteDestinationModalIsOpen] =
useState(false);

Expand Down Expand Up @@ -199,12 +202,7 @@ const ConfigureDestinationForm: FC<ConfigureDestinationFormProps> = ({
</div>
<div className="mb-10 flex flex-row">
<OutlineButton
disabled={
process.env.NEXT_PUBLIC_CONSOLE_BASE_URL ===
"https://demo.instill.tech"
? true
: false
}
disabled={disableResourceDeletion}
onClickHandler={() => setDeleteDestinationModalIsOpen(true)}
position="mr-auto my-auto"
type="button"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { sendAmplitudeData } from "@/lib/amplitude";
import { AxiosError } from "axios";
import { ErrorDetails } from "@/lib/instill/types";
import OutlineButton from "@/components/ui/Buttons/OutlineButton";
import useDeleteResourceGuard from "@/hooks/useDeleteResourceGuard";

export type ConfigureSourceFormProps = {
source: Nullable<SourceWithPipelines>;
Expand Down Expand Up @@ -97,6 +98,8 @@ const ConfigureSourceForm: FC<ConfigureSourceFormProps> = ({ source }) => {
// # #
// ###################################################################

const { disableResourceDeletion } = useDeleteResourceGuard();

const [deleteSourceModalIsOpen, setDeleteSourceModalIsOpen] = useState(false);

const [messageBoxState, setMessageBoxState] =
Expand Down Expand Up @@ -191,12 +194,7 @@ const ConfigureSourceForm: FC<ConfigureSourceFormProps> = ({ source }) => {
</div>
<div className="mb-10 flex flex-row">
<OutlineButton
disabled={
process.env.NEXT_PUBLIC_CONSOLE_BASE_URL ===
"https://demo.instill.tech"
? true
: false
}
disabled={disableResourceDeletion}
onClickHandler={() => setDeleteSourceModalIsOpen(true)}
position="mr-auto my-auto"
type="button"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import OutlineButton from "@/components/ui/Buttons/OutlineButton";
import { DeleteResourceModal } from "@/components/modals";
import { AxiosError } from "axios";
import { ErrorDetails } from "@/lib/instill/types";
import useDeleteResourceGuard from "@/hooks/useDeleteResourceGuard";

export type ConfigureModelFormProps = {
model: Nullable<Model>;
Expand Down Expand Up @@ -142,6 +143,8 @@ const ConfigureModelForm: FC<ConfigureModelFormProps> = ({
// # #
// ###################################################################

const { disableResourceDeletion } = useDeleteResourceGuard();

const modalState = useDeleteResourceModalState();

const deleteModel = useDeleteModel();
Expand Down Expand Up @@ -227,12 +230,7 @@ const ConfigureModelForm: FC<ConfigureModelFormProps> = ({
</div>
<div className="flex flex-row">
<OutlineButton
disabled={
process.env.NEXT_PUBLIC_CONSOLE_BASE_URL ===
"https://demo.instill.tech"
? true
: false
}
disabled={disableResourceDeletion}
onClickHandler={() => modalState.setModalIsOpen(true)}
position="mr-auto my-auto"
type="button"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { sendAmplitudeData } from "@/lib/amplitude";
import { DeleteResourceModal } from "@/components/modals";
import { useRouter } from "next/router";
import OutlineButton from "@/components/ui/Buttons/OutlineButton";
import useDeleteResourceGuard from "@/hooks/useDeleteResourceGuard";

export type ConfigurePipelineFormProps = {
pipeline: Nullable<Pipeline>;
Expand Down Expand Up @@ -136,6 +137,8 @@ const ConfigurePipelineForm: FC<ConfigurePipelineFormProps> = ({
// # #
// ###################################################################

const { disableResourceDeletion } = useDeleteResourceGuard();

const [deletePipelineModalIsOpen, setDeletePipelineModalIsOpen] =
useState(false);

Expand Down Expand Up @@ -264,12 +267,7 @@ const ConfigurePipelineForm: FC<ConfigurePipelineFormProps> = ({
</div>
<div className="mb-10 flex flex-row">
<OutlineButton
disabled={
process.env.NEXT_PUBLIC_CONSOLE_BASE_URL ===
"https://demo.instill.tech"
? true
: false
}
disabled={disableResourceDeletion}
onClickHandler={() => setDeletePipelineModalIsOpen(true)}
position="mr-auto my-auto"
type="button"
Expand Down
20 changes: 20 additions & 0 deletions src/hooks/useDeleteResourceGuard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { useEffect, useState } from "react";

const useDeleteResourceGuard = () => {
const [disableResourceDeletion, setDisableResourceDeletion] = useState(false);

useEffect(() => {
const hostname = new URL(window.location.href).hostname;

if (hostname === "demo.instill.tech") {
setDisableResourceDeletion(true);
return;
}

setDisableResourceDeletion(false);
}, []);

return { disableResourceDeletion };
};

export default useDeleteResourceGuard;
2 changes: 1 addition & 1 deletion src/pages/_document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const Document: FC = () => {
property="twitter:image"
content={`${process.env.NEXT_PUBLIC_CONSOLE_BASE_URL}/images/instill-open-graph.png`}
/>
{process.env.NEXT_PUBLIC_CONSOLE_BASE_URL ===
{`${process.env.NEXT_PUBLIC_CONSOLE_BASE_URL}` ===
"https://demo.instill.tech" ? (
<>
<script
Expand Down