Fix wrong logic for showing confirmation downgrade to free instance change

This commit is contained in:
Joshen Lim committed 2022-12-21 14:05:23 +07:00
1 parent cdbc414405
commit ad300dfd3b
1 file changed
+6 -6
@@ -42,7 +42,7 @@ const ExitSurvey: FC<Props> = ({ freeTier, subscription, onSelectBack }) => {
const [subscriptionPreview, setSubscriptionPreview] = useState<SubscriptionPreview>() const [subscriptionPreview, setSubscriptionPreview] = useState<SubscriptionPreview>()
// Anything above a micro instance size will involve a change in compute size // Anything above a micro instance size will involve a change in compute size
const willChangeComputeSize = (subscription?.addons ?? []).length > 0 // as downgrading back to free will bring the project back to micro
const currentComputeSize = subscription?.addons.find((option) => const currentComputeSize = subscription?.addons.find((option) =>
option.supabase_prod_id.includes('addon_instance') option.supabase_prod_id.includes('addon_instance')
) )
@@ -63,7 +63,7 @@ const ExitSurvey: FC<Props> = ({ freeTier, subscription, onSelectBack }) => {
} }
} }
const getDowngradeSuccessMessage = () => { const getDowngradeRefundMessage = () => {
return `A total of $${returnedAmount} will be refunded as credits on ${billingDate.toLocaleDateString( return `A total of $${returnedAmount} will be refunded as credits on ${billingDate.toLocaleDateString(
'en-US', 'en-US',
{ {
@@ -105,7 +105,7 @@ const ExitSurvey: FC<Props> = ({ freeTier, subscription, onSelectBack }) => {
return return
} }
if (willChangeComputeSize) { if (currentComputeSize !== undefined) {
setMessage(values.message) setMessage(values.message)
return setShowConfirmModal(true) return setShowConfirmModal(true)
} else { } else {
@@ -144,11 +144,11 @@ const ExitSurvey: FC<Props> = ({ freeTier, subscription, onSelectBack }) => {
error: res.error, error: res.error,
}) })
} else { } else {
if (willChangeComputeSize) { if (currentComputeSize !== undefined) {
app.onProjectStatusUpdated(projectId, PROJECT_STATUS.RESTORING) app.onProjectStatusUpdated(projectId, PROJECT_STATUS.RESTORING)
ui.setNotification({ ui.setNotification({
category: 'info', category: 'info',
message: getDowngradeSuccessMessage(), message: getDowngradeRefundMessage(),
duration: 8000, duration: 8000,
}) })
ui.setNotification({ ui.setNotification({
@@ -184,7 +184,7 @@ const ExitSurvey: FC<Props> = ({ freeTier, subscription, onSelectBack }) => {
<UpdateSuccess <UpdateSuccess
projectRef={projectRef || ''} projectRef={projectRef || ''}
title="Your project has been updated" title="Your project has been updated"
message={getDowngradeSuccessMessage()} message={getDowngradeRefundMessage()}
/> />
) )
} }