Skip to content

Commit

Permalink
feat: add warn if categories mismatch
Browse files Browse the repository at this point in the history
  • Loading branch information
uigywnkiub committed Dec 26, 2024
1 parent d058e91 commit 985d21b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
3 changes: 3 additions & 0 deletions app/categories/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export default async function Page() {
const userId = session?.user?.email
const transactions = await getAllTransactions(userId)
const [userCategories] = transactions.map((t) => t.categories).filter(Boolean)
const areCategoriesLengthMismatch =
userCategories.length !== DEFAULT_CATEGORIES.length

const content = (
<>
Expand All @@ -31,6 +33,7 @@ export default async function Page() {
<Categories
userId={userId}
userCategories={userCategories || DEFAULT_CATEGORIES}
areCategoriesLengthMismatch={areCategoriesLengthMismatch}
/>
)}
</div>
Expand Down
20 changes: 18 additions & 2 deletions app/ui/categories/categories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,19 @@ import { HoverableElement } from '../hoverables'
import InfoText from '../info-text'
import Category from './category'

const RESET_CATEGORIES_BTN_TEXT = 'Reset categories'

type TProps = {
userId: TUserId
userCategories: TTransaction['categories']
areCategoriesLengthMismatch: boolean
}

function Categories({ userId, userCategories }: TProps) {
function Categories({
userId,
userCategories,
areCategoriesLengthMismatch,
}: TProps) {
const { isOpen, onOpen, onOpenChange } = useDisclosure()
const [categories, setCategories] = useState(userCategories)
const [editingIndex, setEditingIndex] = useState<number | null>(null)
Expand Down Expand Up @@ -232,9 +239,18 @@ function Categories({ userId, userCategories }: TProps) {
/>
}
>
Reset categories
{RESET_CATEGORIES_BTN_TEXT}
</Button>
</div>
{areCategoriesLengthMismatch && (
<p className='mt-4 text-center text-sm text-warning'>
<PiWarningOctagonFill className='inline animate-pulse' /> We detected
a mismatch between your current categories and the default ones.
<br />
Press &quot;{RESET_CATEGORIES_BTN_TEXT}&quot; to restore the default
and overwrite your current categories.
</p>
)}
<div className='mt-4 flex flex-col gap-2 md:mt-8'>
<InfoText
withDoubleAsterisk
Expand Down

0 comments on commit 985d21b

Please sign in to comment.