-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #75 from websitesieutoc/make-crud-for-pages
Make crud for pages
- Loading branch information
Showing
41 changed files
with
761 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
app/[locale]/(default)/dashboard/dashboard/pages/AddPageButton.tsx
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export default function DashboardPage() { | ||
return 'dashboard will be here'; | ||
return 'dashboard overview will be here'; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Flex, Heading, Spinner, Stack } from '@/components/chakra'; | ||
import { GoBackButton } from '@/components/client'; | ||
import { prisma } from '@/utils/prisma'; | ||
import { Suspense } from 'react'; | ||
|
||
import { PageForm } from '../components'; | ||
|
||
type EditPageProps = { | ||
params: { id: string }; | ||
}; | ||
|
||
export default async function EditPage({ params }: EditPageProps) { | ||
const { id } = params; | ||
|
||
const data = await prisma.page.findUnique({ where: { id } }); | ||
|
||
return ( | ||
<Flex direction="column"> | ||
<Stack direction="row" align="center"> | ||
<GoBackButton path="/dashboard/pages" /> | ||
|
||
<Heading as="h3" size="lg" alignItems="center" color="gray"> | ||
Edit Page | ||
</Heading> | ||
</Stack> | ||
|
||
<Suspense fallback={<Spinner />}> | ||
{data && <PageForm data={data} />} | ||
</Suspense> | ||
</Flex> | ||
); | ||
} |
166 changes: 166 additions & 0 deletions
166
app/[locale]/(default)/dashboard/pages/components/PageForm/DeleteSection.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
import { | ||
AlertDialog, | ||
AlertDialogBody, | ||
AlertDialogCloseButton, | ||
AlertDialogContent, | ||
AlertDialogFooter, | ||
AlertDialogHeader, | ||
AlertDialogOverlay, | ||
Button, | ||
Card, | ||
CardBody, | ||
CardFooter, | ||
CardHeader, | ||
Divider, | ||
Flex, | ||
FormControl, | ||
FormLabel, | ||
Heading, | ||
Input, | ||
Skeleton, | ||
Stack, | ||
Text, | ||
} from '@/components/chakra'; | ||
import { | ||
useColorModeValue, | ||
useDisclosure, | ||
useRef, | ||
useRouter, | ||
useState, | ||
useToast, | ||
} from '@/hooks'; | ||
import { deletePage } from '@/services/pages'; | ||
import type { Page } from '@/types'; | ||
|
||
export type PageDeleteSectionProps = { | ||
page: Page; | ||
}; | ||
|
||
export const DeleteSection = ({ page }: PageDeleteSectionProps) => { | ||
const [isLoading, setIsLoading] = useState(false); | ||
const router = useRouter(); | ||
const toast = useToast(); | ||
const cancelRef = useRef(null); | ||
|
||
const { isOpen, onOpen, onClose } = useDisclosure(); | ||
|
||
const [confirmText, setConfirmText] = useState(''); | ||
|
||
const pageId = page?.id ?? ''; | ||
|
||
const handleCancel = () => { | ||
setConfirmText(''); | ||
onClose(); | ||
}; | ||
|
||
const handleDelete = async () => { | ||
try { | ||
if (!page) return; | ||
|
||
setIsLoading(true); | ||
|
||
await deletePage(pageId); | ||
|
||
toast({ description: 'Delete successfully' }); | ||
|
||
setIsLoading(false); | ||
|
||
onClose(); | ||
|
||
router.refresh(); | ||
router.push('/dashboard/pages'); | ||
} catch (error: any) { | ||
toast({ status: 'error', title: `Error: ${error.message}` }); | ||
} | ||
}; | ||
|
||
const backgroundColor = useColorModeValue('red.50', 'red.900'); | ||
const footerBorder = useColorModeValue('red.100', 'red.600'); | ||
|
||
if (!pageId) { | ||
return <Skeleton height="40px" />; | ||
} | ||
|
||
return ( | ||
<> | ||
<Card bg={backgroundColor} direction="column" width="100%"> | ||
<CardHeader> | ||
<Heading size="md">Delete Page</Heading> | ||
</CardHeader> | ||
|
||
<CardBody> | ||
<Stack spacing={6} maxW="480px" minW="240px"> | ||
<Text> | ||
The page will be permanently deleted. This action is irreversible | ||
and can not be undone. | ||
</Text> | ||
</Stack> | ||
</CardBody> | ||
|
||
<Divider color={footerBorder} /> | ||
|
||
<CardFooter> | ||
<Flex width="100%" direction="row" justify="end"> | ||
<Button | ||
colorScheme="red" | ||
isDisabled={isLoading} | ||
isLoading={isLoading} | ||
onClick={onOpen} | ||
> | ||
Delete | ||
</Button> | ||
</Flex> | ||
</CardFooter> | ||
</Card> | ||
|
||
<AlertDialog | ||
motionPreset="slideInBottom" | ||
leastDestructiveRef={cancelRef} | ||
onClose={onClose} | ||
isOpen={isOpen} | ||
isCentered | ||
> | ||
<AlertDialogOverlay /> | ||
|
||
<AlertDialogContent> | ||
<AlertDialogHeader>Are you sure?</AlertDialogHeader> | ||
<AlertDialogCloseButton /> | ||
<AlertDialogBody> | ||
<FormControl> | ||
<FormLabel> | ||
Confirm by typing:{' '} | ||
<Text as="span" fontWeight="bold"> | ||
YES | ||
</Text> | ||
</FormLabel> | ||
<Input | ||
placeholder="YES" | ||
value={confirmText ?? ''} | ||
onChange={(event) => setConfirmText(event.target.value)} | ||
/> | ||
</FormControl> | ||
</AlertDialogBody> | ||
<AlertDialogFooter> | ||
<Stack direction="row" spacing={3}> | ||
<Button | ||
ref={cancelRef} | ||
isDisabled={isLoading} | ||
onClick={handleCancel} | ||
> | ||
Cancel | ||
</Button> | ||
<Button | ||
isLoading={isLoading} | ||
isDisabled={confirmText !== 'YES' || isLoading} | ||
colorScheme="red" | ||
onClick={handleDelete} | ||
> | ||
Yes, delete it | ||
</Button> | ||
</Stack> | ||
</AlertDialogFooter> | ||
</AlertDialogContent> | ||
</AlertDialog> | ||
</> | ||
); | ||
}; |
Oops, something went wrong.