From 1925955fe2b9533e30d33e104be8d97e2d6f6ae6 Mon Sep 17 00:00:00 2001 From: Joshen Lim Date: Wed, 9 Nov 2022 15:41:31 +0800 Subject: [PATCH] Add restoration failure state --- .../interfaces/Support/SupportForm.tsx | 6 +- .../layouts/ProjectLayout/RestoringState.tsx | 96 ++++++++++++------- studio/lib/constants/infrastructure.ts | 1 + studio/stores/app/ProjectStore.ts | 2 +- 4 files changed, 67 insertions(+), 38 deletions(-) diff --git a/studio/components/interfaces/Support/SupportForm.tsx b/studio/components/interfaces/Support/SupportForm.tsx index 437e1ee771d..deea91401d2 100644 --- a/studio/components/interfaces/Support/SupportForm.tsx +++ b/studio/components/interfaces/Support/SupportForm.tsx @@ -39,7 +39,7 @@ interface Props { const SupportForm: FC = ({ setSentCategory }) => { const { ui, app } = useStore() const router = useRouter() - const { ref, category } = router.query + const { ref, subject, category } = router.query const uploadButtonRef = useRef() const enableFreeSupport = useFlag('enableFreeSupport') @@ -82,7 +82,7 @@ const SupportForm: FC = ({ setSentCategory }) => { const selectedProject = sortedProjects.find((project) => project.ref === ref) const selectedCategory = CATEGORY_OPTIONS.find((option) => { - if (option.value.toLowerCase() === category) return option + if (option.value.toLowerCase() === ((category as string) ?? '').toLowerCase()) return option }) const initialValues = { category: selectedCategory !== undefined ? selectedCategory.value : CATEGORY_OPTIONS[0].value, @@ -94,7 +94,7 @@ const SupportForm: FC = ({ setSentCategory }) => { ? sortedProjects[0].ref : 'no-project', library: 'no-library', - subject: '', + subject: subject ?? '', message: '', } diff --git a/studio/components/layouts/ProjectLayout/RestoringState.tsx b/studio/components/layouts/ProjectLayout/RestoringState.tsx index 05ad1bb45fa..ce1e8130d45 100644 --- a/studio/components/layouts/ProjectLayout/RestoringState.tsx +++ b/studio/components/layouts/ProjectLayout/RestoringState.tsx @@ -1,5 +1,6 @@ +import Link from 'next/link' import { FC, useEffect, useRef, useState } from 'react' -import { Button, IconCheckCircle, IconLoader } from 'ui' +import { Button, IconAlertCircle, IconCheckCircle, IconLoader } from 'ui' import { useStore } from 'hooks' import { API_URL, PROJECT_STATUS } from 'lib/constants' @@ -13,6 +14,7 @@ const RestoringState: FC = ({}) => { const checkServerInterval = useRef() const [loading, setLoading] = useState(false) + const [isFailed, setIsFailed] = useState(false) const [isCompleted, setIsCompleted] = useState(false) useEffect(() => { @@ -28,7 +30,10 @@ const RestoringState: FC = ({}) => { }) if (projectStatus && !projectStatus.error) { const { status } = projectStatus - if (status === PROJECT_STATUS.ACTIVE_HEALTHY) { + if (status === PROJECT_STATUS.RESTORATION_FAILED) { + clearInterval(checkServerInterval.current) + setIsFailed(true) + } else if (status === PROJECT_STATUS.ACTIVE_HEALTHY) { clearInterval(checkServerInterval.current) setIsCompleted(true) } @@ -42,43 +47,66 @@ const RestoringState: FC = ({}) => { return (
-
+
{isCompleted ? ( - <> -
- +
+
+
+ +
+
+

Restoration complete!

+

+ Your project has been successfully restored and is now back online. +

+
-
-

Restoration complete!

-

- Your project has been successfully restored and is now back online. -

+
+
- +
+ ) : isFailed ? ( +
+
+
+ +
+
+

Something went wrong while restoring your project

+

+ Our engineers have already been notified of this, do hang tight while we are + investigating into the issue. +

+
+
+ {isFailed && ( + + )} +
) : ( - <> -
- +
+
+
+ +
+
+

Restoration in progress

+

+ Restoration can take from a few minutes up to several hours depending on the size + of your database. Your project will be offline while the restoration is running. +

+
-
-

Restoration in progress

-

- Restoration can take from a few minutes up to several hours depending on the size of - your database. Your project will be offline while the restoration is running. -

-
- - )} - {isCompleted && ( -
-
)}
diff --git a/studio/lib/constants/infrastructure.ts b/studio/lib/constants/infrastructure.ts index 1def0e4473e..827aac12039 100644 --- a/studio/lib/constants/infrastructure.ts +++ b/studio/lib/constants/infrastructure.ts @@ -105,6 +105,7 @@ export const PROJECT_STATUS = { INIT_FAILED: 'INIT_FAILED', REMOVED: 'REMOVED', RESTORING: 'RESTORING', + RESTORATION_FAILED: 'RESTORATION_FAILED', } export const STRIPE_PRODUCT_IDS: { [x: string]: string } = { diff --git a/studio/stores/app/ProjectStore.ts b/studio/stores/app/ProjectStore.ts index 1cc2ad142c4..d6f13efb066 100644 --- a/studio/stores/app/ProjectStore.ts +++ b/studio/stores/app/ProjectStore.ts @@ -78,7 +78,7 @@ export default class ProjectStore extends PostgresMetaInterface { async fetchSubscriptionTier(project: Project) { const { id: projectId, ref: projectRef, status } = project - if (status === PROJECT_STATUS.ACTIVE_HEALTHY) { + if (status !== PROJECT_STATUS.REMOVED) { const url = `${this.url}/${projectRef}/subscription` const headers = constructHeaders(this.headers) const response = await get(url, { headers })