Files
Gildas Garcia 4f28e5ccb4 chore: migrate Input usages to Shadcn component in settings (#45596)
screens/components

## Screeshots

### Delete project modal textarea
Before:
<img width="792" height="928" alt="image"
src="https://github.com/user-attachments/assets/f8276696-7bc0-415e-958c-b8794762013b"
/>

After:
<img width="788" height="928" alt="image"
src="https://github.com/user-attachments/assets/4b0991c1-7926-4b0a-b1cb-942f809f4a02"
/>

### Edge functions logs search input
Before:
<img width="667" height="219" alt="image"
src="https://github.com/user-attachments/assets/991b09ce-8d4f-4ccc-b787-3da611c78893"
/>

After:
<img width="695" height="231" alt="image"
src="https://github.com/user-attachments/assets/2623faeb-d636-4dec-8244-8e9bdad3acfb"
/>

### Infrastructure
Before:
<img width="1144" height="419" alt="image"
src="https://github.com/user-attachments/assets/25b27819-a3f6-4d67-9edc-f8225d07d592"
/>

After:
<img width="1153" height="440" alt="image"
src="https://github.com/user-attachments/assets/10eea888-09b0-463b-a307-6c58b4feb948"
/>

### DNS Record

Haven't been able to test this one

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Refactor**
* Streamlined form and input layouts across Settings: DNS, Project
Deletion, Infrastructure Info, and Log Preview panels for a more
consistent, accessible editing experience.
* Replaced various single-line inputs with grouped controls,
read-only/display variants, and input-with-addon patterns, improving
readability, copy/readonly behavior, and control affordances (buttons,
badges, tooltips) in settings and log search.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-05-05 18:24:21 +02:00

202 lines
7.4 KiB
TypeScript

import { LOCAL_STORAGE_KEYS } from 'common'
import { useRouter } from 'next/router'
import { useEffect, useState } from 'react'
import { toast } from 'sonner'
import { TextArea_Shadcn_ as TextArea } from 'ui'
import { CANCELLATION_REASONS } from '@/components/interfaces/Billing/Billing.constants'
import { LogicalBackupCliInstructions } from '@/components/layouts/ProjectLayout/LogicalBackupCliInstructions'
import { TextConfirmModal } from '@/components/ui/TextConfirmModalWrapper'
import { useSendDowngradeFeedbackMutation } from '@/data/feedback/exit-survey-send'
import type { OrgProject } from '@/data/projects/org-projects-infinite-query'
import { useProjectDeleteMutation } from '@/data/projects/project-delete-mutation'
import { useOrgSubscriptionQuery } from '@/data/subscriptions/org-subscription-query'
import { useLocalStorageQuery } from '@/hooks/misc/useLocalStorage'
import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization'
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
import type { Organization } from '@/types'
export const DeleteProjectModal = ({
visible,
onClose,
project: projectProp,
organization: organizationProp,
}: {
visible: boolean
onClose: () => void
project?: OrgProject
organization?: Organization
}) => {
const router = useRouter()
const { data: projectFromQuery } = useSelectedProjectQuery()
const { data: organizationFromQuery } = useSelectedOrganizationQuery()
// Use props if provided, otherwise fall back to hooks
const project = projectProp || projectFromQuery
const organization = organizationProp || organizationFromQuery
const [lastVisitedOrganization] = useLocalStorageQuery(
LOCAL_STORAGE_KEYS.LAST_VISITED_ORGANIZATION,
''
)
const projectRef = project?.ref
const { data: subscription } = useOrgSubscriptionQuery({ orgSlug: organization?.slug })
const projectPlan = subscription?.plan?.id ?? 'free'
const isFree = projectPlan === 'free'
const [message, setMessage] = useState<string>('')
const [selectedReason, setSelectedReason] = useState<string[]>([])
// Single select for cancellation reason
const onSelectCancellationReason = (reason: string) => {
setSelectedReason([reason])
}
// Helper to get label for selected reason
const getReasonLabel = (reason: string | undefined) => {
const found = CANCELLATION_REASONS.find((r) => r.value === reason)
return found?.label || 'What can we improve on?'
}
const textareaLabel = getReasonLabel(selectedReason[0])
const [shuffledReasons] = useState(() => [
...CANCELLATION_REASONS.sort(() => Math.random() - 0.5),
{ value: 'None of the above' },
])
const { mutate: deleteProject, isPending: isDeleting } = useProjectDeleteMutation({
onSuccess: async () => {
if (!isFree) {
try {
await sendExitSurvey({
orgSlug: organization?.slug,
projectRef,
message,
reasons: selectedReason.reduce((a, b) => `${a}- ${b}\n`, ''),
exitAction: 'delete',
})
} catch (error) {
// [Joshen] In this case we don't raise any errors if the exit survey fails to send since it shouldn't block the user
}
}
toast.success(`Successfully deleted ${project?.name}`)
// Only redirect if still viewing the deleted project
if (router.asPath.startsWith(`/project/${projectRef}`)) {
if (lastVisitedOrganization) {
router.push(`/org/${lastVisitedOrganization}`)
} else {
router.push('/organizations')
}
}
},
})
const { mutateAsync: sendExitSurvey, isPending: isSending } = useSendDowngradeFeedbackMutation()
const isSubmitting = isDeleting || isSending
async function handleDeleteProject() {
if (project === undefined) return
if (!isFree && selectedReason.length === 0) {
return toast.error('Please select a reason for deleting your project')
}
deleteProject({ projectRef: project.ref, organizationSlug: organization?.slug })
}
useEffect(() => {
if (visible) {
setSelectedReason([])
setMessage('')
}
}, [visible])
return (
<TextConfirmModal
visible={visible}
loading={isSubmitting}
size={isFree ? 'medium' : 'xlarge'}
title={`Confirm deletion of ${project?.name}`}
variant="destructive"
alert={{
title: isFree
? 'This action cannot be undone.'
: `This will permanently delete the ${project?.name}`,
description: !isFree ? `All project data will be lost, and cannot be undone` : '',
}}
text={
isFree
? `This will permanently delete the ${project?.name} project and all of its data.`
: undefined
}
confirmPlaceholder="Type the project name in here"
confirmString={project?.name || ''}
confirmLabel="I understand, delete this project"
onConfirm={handleDeleteProject}
onCancel={() => {
if (!isSubmitting) onClose()
}}
>
<div className="space-y-6">
<LogicalBackupCliInstructions enabled={visible} showResetPassword={false} />
{/*
[Joshen] This is basically ExitSurvey.tsx, ideally we have one shared component but the one
in ExitSurvey has a Form wrapped around it already. Will probably need some effort to refactor
but leaving that for the future.
*/}
{!isFree && (
<>
<div className="space-y-1">
<h4 className="text-base">What made you decide to delete your project?</h4>
</div>
<div className="space-y-4 pt-4">
<div className="flex flex-wrap gap-2" data-toggle="buttons">
{shuffledReasons.map((option) => {
const active = selectedReason[0] === option.value
return (
<label
key={option.value}
className={[
'flex cursor-pointer items-center space-x-2 rounded-md py-1',
'pl-2 pr-3 text-center text-sm shadow-xs transition-all duration-100',
`${
active
? ` bg-foreground text-background opacity-100 hover:bg-foreground/75`
: ` bg-border-strong text-foreground opacity-50 hover:opacity-75`
}`,
].join(' ')}
>
<input
type="radio"
name="options"
value={option.value}
className="hidden"
checked={active}
onChange={() => onSelectCancellationReason(option.value)}
/>
<div>{option.value}</div>
</label>
)
})}
</div>
<div className="text-area-text-sm flex flex-col gap-y-2">
<label htmlFor="message" className="text-sm whitespace-pre-line wrap-break-word">
{textareaLabel}
</label>
<TextArea
name="message"
rows={3}
value={message}
onChange={(event) => setMessage(event.target.value)}
/>
</div>
</div>
</>
)}
</div>
</TextConfirmModal>
)
}