mirror of
https://github.com/ershisan99/flashcards-example-project.git
synced 2025-12-18 12:33:22 +00:00
chore: update deps, apply updated eslint ocnfig
This commit is contained in:
@@ -5,23 +5,23 @@ import { formatDate } from '@/utils'
|
||||
const columns: Column[] = [
|
||||
{
|
||||
key: 'question',
|
||||
title: 'Question',
|
||||
sortable: true,
|
||||
title: 'Question',
|
||||
},
|
||||
{
|
||||
key: 'answer',
|
||||
title: 'Answer',
|
||||
sortable: true,
|
||||
title: 'Answer',
|
||||
},
|
||||
{
|
||||
key: 'updated',
|
||||
title: 'Last Updated',
|
||||
sortable: true,
|
||||
title: 'Last Updated',
|
||||
},
|
||||
{
|
||||
key: 'grade',
|
||||
title: 'Grade',
|
||||
sortable: true,
|
||||
title: 'Grade',
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
import { useState } from 'react'
|
||||
|
||||
import { DeckDialog } from './'
|
||||
import { Button } from '@/components'
|
||||
import { Meta, StoryObj } from '@storybook/react'
|
||||
|
||||
import { DeckDialog } from './'
|
||||
|
||||
import { Button } from '@/components'
|
||||
|
||||
const meta = {
|
||||
title: 'Decks/Deck Dialog',
|
||||
component: DeckDialog,
|
||||
tags: ['autodocs'],
|
||||
title: 'Decks/Deck Dialog',
|
||||
} satisfies Meta<typeof DeckDialog>
|
||||
|
||||
export default meta
|
||||
@@ -17,8 +15,8 @@ type Story = StoryObj<typeof meta>
|
||||
|
||||
export const Default: Story = {
|
||||
args: {
|
||||
open: true,
|
||||
onOpenChange: () => {},
|
||||
open: true,
|
||||
},
|
||||
render: args => {
|
||||
const [open, setOpen] = useState(false)
|
||||
@@ -29,13 +27,13 @@ export const Default: Story = {
|
||||
<Button onClick={() => setOpen(true)}>Open Modal</Button>
|
||||
<DeckDialog
|
||||
{...args}
|
||||
onOpenChange={setOpen}
|
||||
open={open}
|
||||
onCancel={closeModal}
|
||||
onConfirm={data => {
|
||||
console.log(data)
|
||||
closeModal()
|
||||
}}
|
||||
onOpenChange={setOpen}
|
||||
open={open}
|
||||
/>
|
||||
</>
|
||||
)
|
||||
@@ -44,8 +42,8 @@ export const Default: Story = {
|
||||
|
||||
export const WithDefaultValues: Story = {
|
||||
args: {
|
||||
open: true,
|
||||
onOpenChange: () => {},
|
||||
open: true,
|
||||
},
|
||||
render: args => {
|
||||
const [open, setOpen] = useState(false)
|
||||
@@ -57,16 +55,16 @@ export const WithDefaultValues: Story = {
|
||||
<DeckDialog
|
||||
{...args}
|
||||
defaultValues={{
|
||||
name: 'some name',
|
||||
isPrivate: true,
|
||||
name: 'some name',
|
||||
}}
|
||||
onOpenChange={setOpen}
|
||||
open={open}
|
||||
onCancel={closeModal}
|
||||
onConfirm={data => {
|
||||
console.log(data)
|
||||
closeModal()
|
||||
}}
|
||||
onOpenChange={setOpen}
|
||||
open={open}
|
||||
/>
|
||||
</>
|
||||
)
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
import { zodResolver } from '@hookform/resolvers/zod'
|
||||
import { useForm } from 'react-hook-form'
|
||||
|
||||
import { ControlledCheckbox, ControlledTextField, Dialog, DialogProps } from '@/components'
|
||||
import { zodResolver } from '@hookform/resolvers/zod'
|
||||
import { z } from 'zod'
|
||||
|
||||
import s from './deck-dialog.module.scss'
|
||||
|
||||
import { ControlledCheckbox, ControlledTextField, Dialog, DialogProps } from '@/components'
|
||||
|
||||
const newDeckSchema = z.object({
|
||||
name: z.string().min(3).max(50),
|
||||
isPrivate: z.boolean(),
|
||||
name: z.string().min(3).max(50),
|
||||
})
|
||||
|
||||
type FormValues = z.infer<typeof newDeckSchema>
|
||||
|
||||
type Props = Pick<DialogProps, 'onOpenChange' | 'open' | 'onCancel'> & {
|
||||
onConfirm: (data: FormValues) => void
|
||||
type Props = Pick<DialogProps, 'onCancel' | 'onOpenChange' | 'open'> & {
|
||||
defaultValues?: FormValues
|
||||
onConfirm: (data: FormValues) => void
|
||||
}
|
||||
export const DeckDialog = ({
|
||||
onConfirm,
|
||||
onCancel,
|
||||
defaultValues = { isPrivate: false, name: '' },
|
||||
onCancel,
|
||||
onConfirm,
|
||||
...dialogProps
|
||||
}: Props) => {
|
||||
const { control, handleSubmit, reset } = useForm<FormValues>({
|
||||
resolver: zodResolver(newDeckSchema),
|
||||
defaultValues,
|
||||
resolver: zodResolver(newDeckSchema),
|
||||
})
|
||||
const onSubmit = handleSubmit(data => {
|
||||
onConfirm(data)
|
||||
@@ -38,13 +38,13 @@ export const DeckDialog = ({
|
||||
}
|
||||
|
||||
return (
|
||||
<Dialog {...dialogProps} title={'Create new deck'} onConfirm={onSubmit} onCancel={handleCancel}>
|
||||
<Dialog {...dialogProps} onCancel={handleCancel} onConfirm={onSubmit} title={'Create new deck'}>
|
||||
<form className={s.content} onSubmit={onSubmit}>
|
||||
<ControlledTextField name={'name'} control={control} label={'Deck name'} />
|
||||
<ControlledTextField control={control} label={'Deck name'} name={'name'} />
|
||||
<ControlledCheckbox
|
||||
name={'isPrivate'}
|
||||
control={control}
|
||||
label={'Private'}
|
||||
name={'isPrivate'}
|
||||
position={'left'}
|
||||
/>
|
||||
</form>
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import { Link } from 'react-router-dom'
|
||||
|
||||
import s from './decks-table.module.scss'
|
||||
|
||||
import { Edit2Outline, PlayCircleOutline, TrashOutline } from '@/assets'
|
||||
import {
|
||||
Button,
|
||||
@@ -15,6 +13,8 @@ import {
|
||||
} from '@/components'
|
||||
import { Deck } from '@/services/decks'
|
||||
import { formatDate } from '@/utils'
|
||||
|
||||
import s from './decks-table.module.scss'
|
||||
const columns: Column[] = [
|
||||
{
|
||||
key: 'name',
|
||||
@@ -39,12 +39,12 @@ const columns: Column[] = [
|
||||
]
|
||||
|
||||
type Props = {
|
||||
currentUserId: string
|
||||
decks: Deck[] | undefined
|
||||
onDeleteClick: (id: string) => void
|
||||
currentUserId: string
|
||||
onEditClick: (id: string) => void
|
||||
}
|
||||
export const DecksTable = ({ decks, onEditClick, onDeleteClick, currentUserId }: Props) => {
|
||||
export const DecksTable = ({ currentUserId, decks, onDeleteClick, onEditClick }: Props) => {
|
||||
const handleEditClick = (id: string) => () => onEditClick(id)
|
||||
const handleDeleteClick = (id: string) => () => onDeleteClick(id)
|
||||
|
||||
@@ -55,7 +55,7 @@ export const DecksTable = ({ decks, onEditClick, onDeleteClick, currentUserId }:
|
||||
{decks?.map(deck => (
|
||||
<TableRow key={deck.id}>
|
||||
<TableCell>
|
||||
<Typography variant={'body2'} as={Link} to={`/decks/${deck.id}`}>
|
||||
<Typography as={Link} to={`/decks/${deck.id}`} variant={'body2'}>
|
||||
{deck.name}
|
||||
</Typography>
|
||||
</TableCell>
|
||||
@@ -64,15 +64,15 @@ export const DecksTable = ({ decks, onEditClick, onDeleteClick, currentUserId }:
|
||||
<TableCell>{deck.author.name}</TableCell>
|
||||
<TableCell>
|
||||
<div className={s.iconsContainer}>
|
||||
<Button variant={'icon'} as={Link} to={`/decks/${deck.id}/learn`}>
|
||||
<Button as={Link} to={`/decks/${deck.id}/learn`} variant={'icon'}>
|
||||
<PlayCircleOutline />
|
||||
</Button>
|
||||
{deck.author.id === currentUserId && (
|
||||
<>
|
||||
<Button variant={'icon'} onClick={handleEditClick(deck.id)}>
|
||||
<Button onClick={handleEditClick(deck.id)} variant={'icon'}>
|
||||
<Edit2Outline />
|
||||
</Button>
|
||||
<Button variant={'icon'} onClick={handleDeleteClick(deck.id)}>
|
||||
<Button onClick={handleDeleteClick(deck.id)} variant={'icon'}>
|
||||
<TrashOutline />
|
||||
</Button>
|
||||
</>
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
import { useState } from 'react'
|
||||
|
||||
import { DeleteDeckDialog } from './'
|
||||
import { Button } from '@/components'
|
||||
import { Meta, StoryObj } from '@storybook/react'
|
||||
|
||||
import { DeleteDeckDialog } from './'
|
||||
|
||||
import { Button } from '@/components'
|
||||
|
||||
const meta = {
|
||||
title: 'Decks/Delete Deck Dialog',
|
||||
component: DeleteDeckDialog,
|
||||
tags: ['autodocs'],
|
||||
title: 'Decks/Delete Deck Dialog',
|
||||
} satisfies Meta<typeof DeleteDeckDialog>
|
||||
|
||||
export default meta
|
||||
@@ -18,8 +16,8 @@ type Story = StoryObj<typeof meta>
|
||||
export const Default: Story = {
|
||||
args: {
|
||||
deckName: 'Deck Name',
|
||||
open: true,
|
||||
onOpenChange: () => {},
|
||||
open: true,
|
||||
},
|
||||
render: args => {
|
||||
const [open, setOpen] = useState(false)
|
||||
@@ -30,10 +28,10 @@ export const Default: Story = {
|
||||
<Button onClick={() => setOpen(true)}>Open Modal</Button>
|
||||
<DeleteDeckDialog
|
||||
{...args}
|
||||
onOpenChange={setOpen}
|
||||
open={open}
|
||||
onCancel={closeModal}
|
||||
onConfirm={closeModal}
|
||||
onOpenChange={setOpen}
|
||||
open={open}
|
||||
/>
|
||||
</>
|
||||
)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import s from './delete-deck-dialog.module.scss'
|
||||
|
||||
import { Dialog, DialogProps } from '@/components'
|
||||
|
||||
import s from './delete-deck-dialog.module.scss'
|
||||
export default {}
|
||||
type Props = Pick<DialogProps, 'onConfirm' | 'onCancel' | 'open' | 'onOpenChange'> & {
|
||||
type Props = Pick<DialogProps, 'onCancel' | 'onConfirm' | 'onOpenChange' | 'open'> & {
|
||||
deckName: string
|
||||
}
|
||||
export const DeleteDeckDialog = ({ deckName, ...dialogProps }: Props) => {
|
||||
|
||||
Reference in New Issue
Block a user