fix: correct some workflow problems
This commit is contained in:
@@ -56,7 +56,7 @@ export function CreateItemForm({ profile, formAction, tags }: CreateItemProps) {
|
||||
</Select>
|
||||
</FormControl>
|
||||
{profile && (
|
||||
<FormControl variant="outlined">
|
||||
<FormControl variant="outlined" required>
|
||||
<InputLabel id="tag-label">Tag</InputLabel>
|
||||
<Select
|
||||
name="tag"
|
||||
|
||||
@@ -143,6 +143,7 @@ export default function ItemsTable() {
|
||||
type="submit"
|
||||
onClick={handleCreateItemDialog}
|
||||
sx={{ width: '200px' }}
|
||||
disabled={!profile}
|
||||
>
|
||||
Create Item
|
||||
</Button>
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
Typography
|
||||
} from '@mui/material';
|
||||
import { nanoid } from 'nanoid';
|
||||
import { Dispatch, useEffect, useState } from 'react';
|
||||
import { Dispatch, useCallback, useEffect, useState } from 'react';
|
||||
import { useFormState } from 'react-dom';
|
||||
import { Profiles } from '../../../../data/types';
|
||||
import { CreateProfileAction } from './actions/CreateProfileAction';
|
||||
@@ -51,6 +51,11 @@ export default function ProfilesTable({
|
||||
fetchProfiles();
|
||||
}, [formState, refreshKey]);
|
||||
|
||||
const handleDelete = useCallback(async () => {
|
||||
setRefreshKey((prevKey) => prevKey + 1);
|
||||
setSelectedProfile(undefined);
|
||||
}, [setSelectedProfile]);
|
||||
|
||||
return (
|
||||
<Stack
|
||||
sx={{
|
||||
@@ -78,6 +83,7 @@ export default function ProfilesTable({
|
||||
<TableHead>
|
||||
<TableRow sx={{ '& th': { textAlign: 'center' } }}>
|
||||
<TableCell>Name</TableCell>
|
||||
<TableCell>Creation date</TableCell>
|
||||
<TableCell>Delete</TableCell>
|
||||
</TableRow>
|
||||
</TableHead>
|
||||
@@ -89,7 +95,7 @@ export default function ProfilesTable({
|
||||
profile={profile}
|
||||
selected={selectedProfile}
|
||||
setSelected={setSelectedProfile}
|
||||
onDelete={() => setRefreshKey((prevKey) => prevKey + 1)}
|
||||
onDelete={handleDelete}
|
||||
/>
|
||||
))}
|
||||
</TableBody>
|
||||
|
||||
@@ -55,13 +55,17 @@ export default function ProfilesTableRow({
|
||||
};
|
||||
|
||||
return (
|
||||
<TableRow key={profile.id}>
|
||||
<TableCell
|
||||
align="center"
|
||||
onClick={handleClick}
|
||||
onDoubleClick={handleDoubleClick}
|
||||
sx={{ bgcolor: profile.id === selected ? 'lightblue' : 'inherit' }}
|
||||
>
|
||||
<TableRow
|
||||
sx={{
|
||||
'& td': {
|
||||
textAlign: 'center',
|
||||
bgcolor: profile.id === selected ? 'lightblue' : 'inherit'
|
||||
}
|
||||
}}
|
||||
onClick={handleClick}
|
||||
key={profile.id}
|
||||
>
|
||||
<TableCell onDoubleClick={handleDoubleClick}>
|
||||
{isEditing ? (
|
||||
<TextField
|
||||
value={name}
|
||||
@@ -73,7 +77,8 @@ export default function ProfilesTableRow({
|
||||
name
|
||||
)}
|
||||
</TableCell>
|
||||
<TableCell align="center">
|
||||
<TableCell>{new Date(profile.createdAt).toLocaleString()}</TableCell>
|
||||
<TableCell>
|
||||
<Button onClick={handleDelete}>Delete</Button>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
|
||||
@@ -40,6 +40,8 @@ export default function TagsTable({ selectedProfile }: TagsTableProps) {
|
||||
} catch (error) {
|
||||
console.error("Couldn't fetch tags.");
|
||||
}
|
||||
} else {
|
||||
setTags([]);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -82,6 +84,7 @@ export default function TagsTable({ selectedProfile }: TagsTableProps) {
|
||||
<TableHead>
|
||||
<TableRow sx={{ '& th': { textAlign: 'center' } }}>
|
||||
<TableCell>Name</TableCell>
|
||||
<TableCell>Creation date</TableCell>
|
||||
<TableCell>Delete</TableCell>
|
||||
</TableRow>
|
||||
</TableHead>
|
||||
|
||||
@@ -57,8 +57,11 @@ export default function TagsTableRow({ tag, onDelete }: TagsTableRowProps) {
|
||||
name
|
||||
)}
|
||||
</TableCell>
|
||||
<TableCell>{new Date(tag.createdAt).toLocaleString()}</TableCell>
|
||||
<TableCell>
|
||||
<Button onClick={handleDelete}>Delete</Button>
|
||||
<Button onClick={handleDelete} disabled={tag.Items > 0}>
|
||||
Delete
|
||||
</Button>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
);
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
import { z } from 'zod';
|
||||
import { initializeUser } from '../../../../../data/initializeUser';
|
||||
import { Profiles } from '../../../../../data/types';
|
||||
import prisma from '../../../../../prisma/prisma';
|
||||
|
||||
interface TagsActionProps {
|
||||
@@ -19,7 +18,7 @@ export async function TagsAction({ selectedProfile }: TagsActionProps) {
|
||||
const user = await initializeUser();
|
||||
|
||||
try {
|
||||
const profiles = await prisma.tag.findMany({
|
||||
const tags = await prisma.tag.findMany({
|
||||
where: {
|
||||
Profile: {
|
||||
User: {
|
||||
@@ -28,12 +27,22 @@ export async function TagsAction({ selectedProfile }: TagsActionProps) {
|
||||
id: selectedProfile
|
||||
}
|
||||
},
|
||||
include: {
|
||||
Items: {
|
||||
select: {
|
||||
id: true
|
||||
}
|
||||
}
|
||||
},
|
||||
orderBy: {
|
||||
createdAt: 'desc'
|
||||
}
|
||||
});
|
||||
|
||||
return profiles as Profiles;
|
||||
return tags.map((tag) => ({
|
||||
...tag,
|
||||
Items: tag.Items.length
|
||||
}));
|
||||
} catch (error) {
|
||||
throw new Error('Failed to find tags');
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ export const CreateProfileFormSchema = z.object({
|
||||
export const ProfileSchema = z.object({
|
||||
id: z.string(),
|
||||
name: z.string(),
|
||||
createdAt: z.date().optional()
|
||||
createdAt: z.date()
|
||||
});
|
||||
|
||||
export type Profile = z.infer<typeof ProfileSchema>;
|
||||
@@ -85,7 +85,8 @@ export const CreateTagFormSchema = z.object({
|
||||
export const TagSchema = z.object({
|
||||
id: z.string(),
|
||||
name: z.string(),
|
||||
createdAt: z.date().optional()
|
||||
Items: z.number(),
|
||||
createdAt: z.date()
|
||||
});
|
||||
|
||||
export type Tag = z.infer<typeof TagSchema>;
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
"typecheck": "tsc --noEmit",
|
||||
"prepare": "husky install",
|
||||
"migrate": "npx prisma migrate dev",
|
||||
"push": "npx prisma db push",
|
||||
"generate": "npx prisma generate",
|
||||
"reset": "npx prisma db push --force-reset"
|
||||
},
|
||||
@@ -51,10 +50,10 @@
|
||||
"typescript": "^5"
|
||||
},
|
||||
"lint-staged": {
|
||||
"*.ts": [
|
||||
"*.(ts,tsx)": [
|
||||
"eslint --quiet --fix"
|
||||
],
|
||||
"*.{json,ts}": [
|
||||
"*.{json,ts,tsx}": [
|
||||
"prettier --write --ignore-unknown"
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user