♻ Move project source files to top level from src, update Sentry dependency (#630)

Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
This commit is contained in:
Esteban Maya
2024-03-07 11:35:33 -05:00
committed by GitHub
parent ae83b89113
commit 8558cf00a2
248 changed files with 4 additions and 6 deletions

View File

@@ -0,0 +1,29 @@
import React from 'react';
import { Badge, Container, Heading, Radio, RadioGroup, Stack, useColorMode } from '@chakra-ui/react';
const Appearance: React.FC = () => {
const { colorMode, toggleColorMode } = useColorMode();
return (
<>
<Container maxW='full'>
<Heading size='sm' py={4}>
Appearance
</Heading>
<RadioGroup onChange={toggleColorMode} value={colorMode}>
<Stack>
{/* TODO: Add system default option */}
<Radio value='light' colorScheme='teal'>
Light mode<Badge ml='1' colorScheme='teal'>Default</Badge>
</Radio>
<Radio value='dark' colorScheme='teal'>
Dark mode
</Radio>
</Stack>
</RadioGroup>
</Container>
</>
);
}
export default Appearance;

View File

@@ -0,0 +1,58 @@
import React from 'react';
import { Box, Button, Container, FormControl, FormLabel, Heading, Input, useColorModeValue } from '@chakra-ui/react';
import { SubmitHandler, useForm } from 'react-hook-form';
import { ApiError, UpdatePassword } from '../../client';
import useCustomToast from '../../hooks/useCustomToast';
import { useUserStore } from '../../store/user-store';
interface UpdatePasswordForm extends UpdatePassword {
confirm_password: string;
}
const ChangePassword: React.FC = () => {
const color = useColorModeValue('gray.700', 'white');
const showToast = useCustomToast();
const { register, handleSubmit, reset, formState: { isSubmitting } } = useForm<UpdatePasswordForm>();
const { editPassword } = useUserStore();
const onSubmit: SubmitHandler<UpdatePasswordForm> = async (data) => {
try {
await editPassword(data);
showToast('Success!', 'Password updated.', 'success');
reset();
} catch (err) {
const errDetail = (err as ApiError).body.detail;
showToast('Something went wrong.', `${errDetail}`, 'error');
}
}
return (
<>
<Container maxW='full' as='form' onSubmit={handleSubmit(onSubmit)}>
<Heading size='sm' py={4}>
Change Password
</Heading>
<Box w={{ 'sm': 'full', 'md': '50%' }}>
<FormControl>
<FormLabel color={color} htmlFor='currentPassword'>Current password</FormLabel>
<Input id='currentPassword' {...register('current_password')} placeholder='••••••••' type='password' />
</FormControl>
<FormControl mt={4}>
<FormLabel color={color} htmlFor='newPassword'>New password</FormLabel>
<Input id='newPassword' {...register('new_password')} placeholder='••••••••' type='password' />
</FormControl>
<FormControl mt={4}>
<FormLabel color={color} htmlFor='confirmPassword'>Confirm new password</FormLabel>
<Input id='confirmPassword' {...register('confirm_password')} placeholder='••••••••' type='password' />
</FormControl>
<Button bg='ui.main' color='white' _hover={{ opacity: 0.8 }} mt={4} type='submit' isLoading={isSubmitting}>
Save
</Button>
</Box>
</ Container>
</>
);
}
export default ChangePassword;

View File

@@ -0,0 +1,27 @@
import React from 'react';
import { Button, Container, Heading, Text, useDisclosure } from '@chakra-ui/react';
import DeleteConfirmation from './DeleteConfirmation';
const DeleteAccount: React.FC = () => {
const confirmationModal = useDisclosure();
return (
<>
<Container maxW='full'>
<Heading size='sm' py={4}>
Delete Account
</Heading>
<Text>
Are you sure you want to delete your account? This action cannot be undone.
</Text>
<Button bg='ui.danger' color='white' _hover={{ opacity: 0.8 }} mt={4} onClick={confirmationModal.onOpen}>
Delete
</Button>
<DeleteConfirmation isOpen={confirmationModal.isOpen} onClose={confirmationModal.onClose} />
</ Container>
</>
);
}
export default DeleteAccount;

View File

@@ -0,0 +1,72 @@
import React from 'react';
import { AlertDialog, AlertDialogBody, AlertDialogContent, AlertDialogFooter, AlertDialogHeader, AlertDialogOverlay, Button } from '@chakra-ui/react';
import { useForm } from 'react-hook-form';
import { ApiError } from '../../client';
import useAuth from '../../hooks/useAuth';
import useCustomToast from '../../hooks/useCustomToast';
import { useUserStore } from '../../store/user-store';
interface DeleteProps {
isOpen: boolean;
onClose: () => void;
}
const DeleteConfirmation: React.FC<DeleteProps> = ({ isOpen, onClose }) => {
const showToast = useCustomToast();
const cancelRef = React.useRef<HTMLButtonElement | null>(null);
const { handleSubmit, formState: { isSubmitting } } = useForm();
const { user, deleteUser } = useUserStore();
const { logout } = useAuth();
const onSubmit = async () => {
try {
await deleteUser(user!.id);
logout();
onClose();
showToast('Success', 'Your account has been successfully deleted.', 'success');
} catch (err) {
const errDetail = (err as ApiError).body.detail;
showToast('Something went wrong.', `${errDetail}`, 'error');
}
}
return (
<>
<AlertDialog
isOpen={isOpen}
onClose={onClose}
leastDestructiveRef={cancelRef}
size={{ base: 'sm', md: 'md' }}
isCentered
>
<AlertDialogOverlay>
<AlertDialogContent as='form' onSubmit={handleSubmit(onSubmit)}>
<AlertDialogHeader>
Confirmation Required
</AlertDialogHeader>
<AlertDialogBody>
All your account data will be <strong>permanently deleted.</strong> If you are sure, please click <strong>'Confirm'</strong> to proceed.
</AlertDialogBody>
<AlertDialogFooter gap={3}>
<Button bg='ui.danger' color='white' _hover={{ opacity: 0.8 }} type='submit' isLoading={isSubmitting}>
Confirm
</Button>
<Button ref={cancelRef} onClick={onClose} isDisabled={isSubmitting}>
Cancel
</Button>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialogOverlay>
</AlertDialog >
</>
)
}
export default DeleteConfirmation;

View File

@@ -0,0 +1,88 @@
import React, { useState } from 'react';
import { Box, Button, Container, Flex, FormControl, FormLabel, Heading, Input, Text, useColorModeValue } from '@chakra-ui/react';
import { SubmitHandler, useForm } from 'react-hook-form';
import { ApiError, UserOut, UserUpdateMe } from '../../client';
import useCustomToast from '../../hooks/useCustomToast';
import { useUserStore } from '../../store/user-store';
import { useUsersStore } from '../../store/users-store';
const UserInformation: React.FC = () => {
const color = useColorModeValue('gray.700', 'white');
const showToast = useCustomToast();
const [editMode, setEditMode] = useState(false);
const { register, handleSubmit, reset, formState: { isSubmitting } } = useForm<UserOut>();
const { user, editUser } = useUserStore();
const { getUsers } = useUsersStore();
const toggleEditMode = () => {
setEditMode(!editMode);
};
const onSubmit: SubmitHandler<UserUpdateMe> = async (data) => {
try {
await editUser(data);
await getUsers()
showToast('Success!', 'User updated successfully.', 'success');
} catch (err) {
const errDetail = (err as ApiError).body.detail;
showToast('Something went wrong.', `${errDetail}`, 'error');
}
}
const onCancel = () => {
reset();
toggleEditMode();
}
return (
<>
<Container maxW='full' as='form' onSubmit={handleSubmit(onSubmit)}>
<Heading size='sm' py={4}>
User Information
</Heading>
<Box w={{ 'sm': 'full', 'md': '50%' }}>
<FormControl>
<FormLabel color={color} htmlFor='name'>Full name</FormLabel>
{
editMode ?
<Input id='name' {...register('full_name')} defaultValue={user?.full_name} type='text' size='md' /> :
<Text size='md' py={2}>
{user?.full_name || 'N/A'}
</Text>
}
</FormControl>
<FormControl mt={4}>
<FormLabel color={color} htmlFor='email'>Email</FormLabel>
{
editMode ?
<Input id='email' {...register('email')} defaultValue={user?.email} type='text' size='md' /> :
<Text size='md' py={2}>
{user?.email || 'N/A'}
</Text>
}
</FormControl>
<Flex mt={4} gap={3}>
<Button
bg='ui.main'
color='white'
_hover={{ opacity: 0.8 }}
onClick={toggleEditMode}
type={editMode ? 'button' : 'submit'}
isLoading={editMode ? isSubmitting : false}
>
{editMode ? 'Save' : 'Edit'}
</Button>
{editMode &&
<Button onClick={onCancel} isDisabled={isSubmitting}>
Cancel
</Button>}
</Flex>
</Box>
</ Container>
</>
);
}
export default UserInformation;