-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:blenderskool/diode into partial-query
- Loading branch information
Showing
16 changed files
with
771 additions
and
346 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Tag, TagProps } from '@chakra-ui/react'; | ||
import { ApiMethod } from '@prisma/client'; | ||
|
||
type Props = TagProps & { | ||
method: ApiMethod; | ||
}; | ||
|
||
const config: Record<ApiMethod, TagProps> = { | ||
GET: { | ||
children: "GET", | ||
colorScheme: "green", | ||
}, | ||
POST: { | ||
children: "POST", | ||
colorScheme: "yellow", | ||
}, | ||
PUT: { | ||
children: "PUT", | ||
colorScheme: "blue", | ||
}, | ||
DELETE: { | ||
children: "DEL", | ||
colorScheme: "red", | ||
}, | ||
}; | ||
|
||
export default function ApiMethodTag({ method, ...props }: Props) { | ||
return <Tag flexShrink={0} {...config[method]} {...props} />; | ||
} |
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,13 +1,13 @@ | ||
import { Button } from '@chakra-ui/react'; | ||
import { ArrowBackIcon } from '@chakra-ui/icons'; | ||
import { ChevronLeftIcon } from '@heroicons/react/outline'; | ||
import { useRouter } from 'next/router'; | ||
|
||
export default function BackLink(props) { | ||
const router = useRouter(); | ||
|
||
return ( | ||
<div> | ||
<Button variant="link" leftIcon={<ArrowBackIcon />} onClick={router.back} {...props} /> | ||
<Button variant="link" leftIcon={<ChevronLeftIcon width="16" />} onClick={router.back} {...props} /> | ||
</div> | ||
) | ||
} |
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,109 @@ | ||
import { | ||
AlertDialog, | ||
AlertDialogBody, | ||
AlertDialogContent, | ||
AlertDialogFooter, | ||
AlertDialogHeader, | ||
AlertDialogOverlay, | ||
Button, | ||
ChakraProvider | ||
} from '@chakra-ui/react'; | ||
import { useRef } from 'react'; | ||
import { render, unmountComponentAtNode } from 'react-dom'; | ||
|
||
import theme from '@/lib/chakra-theme'; | ||
|
||
type ConfirmDialogOptions = { | ||
title: string; | ||
description: string; | ||
btnConfirmTxt: string; | ||
}; | ||
|
||
type AlertComponentProps = ConfirmDialogOptions & { | ||
onCancel: () => any; | ||
onConfirm: () => any; | ||
}; | ||
|
||
function AlertComponent({ | ||
title, | ||
description, | ||
btnConfirmTxt, | ||
onCancel, | ||
onConfirm | ||
}: AlertComponentProps) { | ||
const cancelRef = useRef(); | ||
|
||
return ( | ||
<ChakraProvider theme={theme}> | ||
<AlertDialog isOpen leastDestructiveRef={cancelRef} onClose={onCancel}> | ||
<AlertDialogOverlay> | ||
<AlertDialogContent> | ||
<AlertDialogHeader fontFamily="heading" fontWeight="700" fontSize="2xl"> | ||
{title} | ||
</AlertDialogHeader> | ||
|
||
<AlertDialogBody color="gray.500" fontSize="sm"> | ||
{description} | ||
</AlertDialogBody> | ||
|
||
<AlertDialogFooter> | ||
<Button ref={cancelRef} onClick={onCancel}> | ||
Cancel | ||
</Button> | ||
<Button colorScheme="red" onClick={onConfirm} ml="4"> | ||
{btnConfirmTxt} | ||
</Button> | ||
</AlertDialogFooter> | ||
</AlertDialogContent> | ||
</AlertDialogOverlay> | ||
</AlertDialog> | ||
</ChakraProvider> | ||
); | ||
} | ||
|
||
/** | ||
* Helper function to show confirm dialog | ||
* @param param0 Options for confirm dialog shown | ||
* @returns Promise which resolves to a boolean indicating whether user confirmed the action | ||
*/ | ||
function confirmDialog({ | ||
title = 'Are you sure?', | ||
description = 'This action is irreversible.', | ||
btnConfirmTxt = 'Confirm', | ||
}: Partial<ConfirmDialogOptions>) { | ||
let container = document.getElementById('alert-dialog'); | ||
if (!container) { | ||
container = document.createElement('div'); | ||
container.id = 'alert-dialog'; | ||
document.body.appendChild(container); | ||
} | ||
|
||
return new Promise<boolean>((resolve) => { | ||
const close = () => { | ||
unmountComponentAtNode(container); | ||
container.remove(); | ||
}; | ||
|
||
const handleCancel = () => { | ||
close(); | ||
resolve(false); | ||
}; | ||
const handleConfirm = () => { | ||
close(); | ||
resolve(true); | ||
}; | ||
|
||
render( | ||
<AlertComponent | ||
title={title} | ||
description={description} | ||
btnConfirmTxt={btnConfirmTxt} | ||
onCancel={handleCancel} | ||
onConfirm={handleConfirm} | ||
/>, | ||
container | ||
); | ||
}); | ||
} | ||
|
||
export default confirmDialog; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { extendTheme, ThemeConfig } from '@chakra-ui/react'; | ||
|
||
const theme = extendTheme({ | ||
config: { | ||
initialColorMode: 'light', | ||
useSystemColorMode: false, | ||
}, | ||
fonts: { | ||
heading: "Raleway", | ||
body: "Inter", | ||
}, | ||
} as ThemeConfig); | ||
|
||
|
||
export default theme; |
Oops, something went wrong.