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

making error displays in dialog reusable #28

Merged
merged 1 commit into from
Dec 20, 2024
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
Expand Up @@ -16,7 +16,8 @@ import { useMutation, useQueryClient } from '@tanstack/react-query'
import { UpdateCoursePhase } from '@/interfaces/course_phase'
import { updateCoursePhase } from '../../../network/mutations/updateCoursePhase'
import { useParams } from 'react-router-dom'
import { AlertCircle, Loader2 } from 'lucide-react'
import { DialogLoadingDisplay } from '@/components/dialog/DialogLoadingDisplay'
import { DialogErrorDisplay } from '@/components/dialog/DialogErrorDisplay'

interface ApplicationConfigDialogProps {
isOpen: boolean
Expand Down Expand Up @@ -71,20 +72,9 @@ export function ApplicationConfigDialog({
<Dialog open={isOpen} onOpenChange={onClose}>
<DialogContent>
{isPending ? (
<div className='flex flex-col items-center justify-center h-48'>
<Loader2 className='h-10 w-10 text-primary animate-spin' />
<p className='mt-4 text-lg font-medium text-muted-foreground'>
Saving application config...
</p>
</div>
<DialogLoadingDisplay customMessage='Saving application config...' />
) : isMutateError ? (
<div className='flex flex-col items-center justify-center h-48'>
<AlertCircle className='h-10 w-10 text-destructive' />
<p className='mt-4 text-lg font-medium text-destructive'>Error: {error.message}</p>
<p className='mt-2 text-sm text-muted-foreground'>
Please try again or contact support if the problem persists.
</p>
</div>
<DialogErrorDisplay error={error} />
) : (
<>
<DialogHeader>
Expand Down
16 changes: 4 additions & 12 deletions clients/core/src/Course/AddingCourse/AddCourseDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ import { useMutation, useQueryClient } from '@tanstack/react-query'
import { PostCourse } from '@/interfaces/post_course'
import { postNewCourse } from '../../network/mutations/postNewCourse'
import { useNavigate } from 'react-router-dom'
import { AlertCircle, Loader2 } from 'lucide-react'
import { useKeycloak } from '@/keycloak/useKeycloak'
import { DialogLoadingDisplay } from '@/components/dialog/DialogLoadingDisplay'
import { DialogErrorDisplay } from '@/components/dialog/DialogErrorDisplay'

interface AddCourseDialogProps {
children: React.ReactNode
Expand Down Expand Up @@ -112,18 +113,9 @@ export const AddCourseDialog: React.FC<AddCourseDialogProps> = ({ children }) =>
<DialogTrigger asChild>{children}</DialogTrigger>
<DialogContent className='sm:max-w-[550px]'>
{isPending ? (
<div className='flex flex-col items-center justify-center h-48'>
<Loader2 className='h-10 w-10 text-primary animate-spin' />
<p className='mt-4 text-lg font-medium text-muted-foreground'>Loading course data...</p>
</div>
<DialogLoadingDisplay customMessage='Updating course data...' />
) : isError ? (
<div className='flex flex-col items-center justify-center h-48'>
<AlertCircle className='h-10 w-10 text-destructive' />
<p className='mt-4 text-lg font-medium text-destructive'>Error: {error.message}</p>
<p className='mt-2 text-sm text-muted-foreground'>
Please try again or contact support if the problem persists.
</p>
</div>
<DialogErrorDisplay error={error} />
) : (
<>
<DialogHeader>
Expand Down
21 changes: 21 additions & 0 deletions clients/shared_library/components/dialog/DialogErrorDisplay.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { AlertCircle } from 'lucide-react'

interface DialogErrorDisplayProps {
customMessage?: string
error: Error
}

export const DialogErrorDisplay = ({
customMessage,
error,
}: DialogErrorDisplayProps): JSX.Element => {
return (
<div className='flex flex-col items-center justify-center h-48'>
<AlertCircle className='h-10 w-10 text-destructive' />
<p className='mt-4 text-lg font-medium text-destructive'>Error: {error.message}</p>
<p className='mt-2 text-sm text-muted-foreground'>
{customMessage ?? 'Please try again or contact the administrators if the problem persists.'}
</p>
</div>
)
}
16 changes: 16 additions & 0 deletions clients/shared_library/components/dialog/DialogLoadingDisplay.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Loader2 } from 'lucide-react'

interface DialogLoadingDisplayProps {
customMessage?: string
}

export const DialogLoadingDisplay = ({ customMessage }: DialogLoadingDisplayProps): JSX.Element => {
return (
<div className='flex flex-col items-center justify-center h-48'>
<Loader2 className='h-10 w-10 text-primary animate-spin' />
<p className='mt-4 text-lg font-medium text-muted-foreground'>
{customMessage ?? 'Loading...'}
</p>
</div>
)
}
Loading