Compare commits
	
		
			2 Commits
		
	
	
		
			c0f85e89fd
			...
			4459b9d644
		
	
	| Author | SHA1 | Date | 
|---|---|---|
| 
							
							
								
								 | 
						4459b9d644 | |
| 
							
							
								
								 | 
						ae4e1685c5 | 
							
								
								
									
										
											BIN
										
									
								
								prisma/dev.db
								
								
								
								
							
							
						
						
									
										
											BIN
										
									
								
								prisma/dev.db
								
								
								
								
							
										
											Binary file not shown.
										
									
								
							| 
						 | 
					@ -1,8 +1,9 @@
 | 
				
			||||||
import { getGenres, getPubs, getResponses, getStories, getSubsComplete } from "app/lib/get"
 | 
					import { getGenres, getPubs, getPubsWithGenres, getResponses, getStories, getStoriesWithGenres, getSubsComplete } from "app/lib/get"
 | 
				
			||||||
import { DataTable } from "app/ui/tables/data-table"
 | 
					import { DataTable } from "app/ui/tables/data-table"
 | 
				
			||||||
import { columns } from "./columns"
 | 
					import { columns } from "./columns"
 | 
				
			||||||
import { Pub, Response, Story, Sub } from "@prisma/client"
 | 
					import { Genre, Pub, Response, Story, Sub } from "@prisma/client"
 | 
				
			||||||
import CreateSubmissionDialog from "./create"
 | 
					import CreateSubmissionDialog from "./create"
 | 
				
			||||||
 | 
					import { PubWithGenres } from "app/publication/page"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export type SubComplete = Sub & {
 | 
					export type SubComplete = Sub & {
 | 
				
			||||||
  pub: Pub,
 | 
					  pub: Pub,
 | 
				
			||||||
| 
						 | 
					@ -12,10 +13,10 @@ export type SubComplete = Sub & {
 | 
				
			||||||
export default async function Page() {
 | 
					export default async function Page() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const subs: Array<SubComplete> = await getSubsComplete()
 | 
					  const subs: Array<SubComplete> = await getSubsComplete()
 | 
				
			||||||
  const stories = await getStories()
 | 
					  const stories: Story[] = await getStoriesWithGenres()
 | 
				
			||||||
  const pubs = await getPubs()
 | 
					  const pubs: PubWithGenres[] = await getPubsWithGenres()
 | 
				
			||||||
  const responses = await getResponses()
 | 
					  const responses: Response[] = await getResponses()
 | 
				
			||||||
  const genres = await getGenres()
 | 
					  const genres: Genre[] = await getGenres()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return (
 | 
					  return (
 | 
				
			||||||
    <div className="container px-1 md:px-4 mx-auto">
 | 
					    <div className="container px-1 md:px-4 mx-auto">
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -706,16 +706,12 @@ body {
 | 
				
			||||||
  z-index: 100;
 | 
					  z-index: 100;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.m-auto {
 | 
					 | 
				
			||||||
  margin: auto;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
.m-6 {
 | 
					.m-6 {
 | 
				
			||||||
  margin: 1.5rem;
 | 
					  margin: 1.5rem;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.m-12 {
 | 
					.m-auto {
 | 
				
			||||||
  margin: 3rem;
 | 
					  margin: auto;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.-mx-1 {
 | 
					.-mx-1 {
 | 
				
			||||||
| 
						 | 
					@ -758,10 +754,6 @@ body {
 | 
				
			||||||
  margin-bottom: auto;
 | 
					  margin-bottom: auto;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.mb-6 {
 | 
					 | 
				
			||||||
  margin-bottom: 1.5rem;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
.ml-2 {
 | 
					.ml-2 {
 | 
				
			||||||
  margin-left: 0.5rem;
 | 
					  margin-left: 0.5rem;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -1150,16 +1142,12 @@ body {
 | 
				
			||||||
  gap: 0.5rem;
 | 
					  gap: 0.5rem;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.gap-4 {
 | 
					 | 
				
			||||||
  gap: 1rem;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
.gap-3 {
 | 
					.gap-3 {
 | 
				
			||||||
  gap: 0.75rem;
 | 
					  gap: 0.75rem;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.gap-12 {
 | 
					.gap-4 {
 | 
				
			||||||
  gap: 3rem;
 | 
					  gap: 1rem;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.gap-x-16 {
 | 
					.gap-x-16 {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -36,12 +36,14 @@ import { createSub } from "app/lib/create"
 | 
				
			||||||
import { subSchema } from "./schemas"
 | 
					import { subSchema } from "./schemas"
 | 
				
			||||||
import { useRouter } from "next/navigation"
 | 
					import { useRouter } from "next/navigation"
 | 
				
			||||||
import { Ban } from "lucide-react"
 | 
					import { Ban } from "lucide-react"
 | 
				
			||||||
import { Story } from "@prisma/client"
 | 
					import { Pub, Response, Story, Sub } from "@prisma/client"
 | 
				
			||||||
 | 
					import { StoryWithGenres } from "app/story/page"
 | 
				
			||||||
 | 
					import { PubWithGenres } from "app/publication/page"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export type SubForm = z.infer<typeof subSchema>
 | 
					export type SubForm = z.infer<typeof subSchema>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default function SubmissionForm({ stories, pubs, responses, defaults, closeDialog }: { stories: any, pubs: any, responses: any, defaults?: any, closeDialog?: () => void }) {
 | 
					export default function SubmissionForm({ stories, pubs, responses, defaults, closeDialog }: { stories: StoryWithGenres[], pubs: PubWithGenres[], responses: Response[], defaults?: Sub, closeDialog?: () => void }) {
 | 
				
			||||||
	const form = useForm<z.infer<typeof subSchema>>({
 | 
						const form = useForm<z.infer<typeof subSchema>>({
 | 
				
			||||||
		resolver: zodResolver(subSchema),
 | 
							resolver: zodResolver(subSchema),
 | 
				
			||||||
		defaultValues: {
 | 
							defaultValues: {
 | 
				
			||||||
| 
						 | 
					@ -51,19 +53,41 @@ export default function SubmissionForm({ stories, pubs, responses, defaults, clo
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
	const [isSubCalendarOpen, setIsSubCalendarOpen] = useState(false);
 | 
						const [isSubCalendarOpen, setIsSubCalendarOpen] = useState(false);
 | 
				
			||||||
	const [isRespCalendarOpen, setIsRespCalendarOpen] = useState(false);
 | 
						const [isRespCalendarOpen, setIsRespCalendarOpen] = useState(false);
 | 
				
			||||||
 | 
						const [relevantPubIds, setRelevantPubIds] = useState(pubs.map(e => e.id));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						function updateRelevantPubs(storyId: number) {
 | 
				
			||||||
 | 
							console.log("storyId: " + storyId)
 | 
				
			||||||
 | 
							console.log("stories: ", stories)
 | 
				
			||||||
 | 
							const story = stories.find(e => e.id == storyId)
 | 
				
			||||||
 | 
							console.log("story: ", story)
 | 
				
			||||||
 | 
							const storyGenreIds = story?.genres.map(e => e.id) ?? []
 | 
				
			||||||
 | 
							const relevantPubIds = pubs.filter(e => {
 | 
				
			||||||
 | 
								const pubGenreIds = e.genres.map(e => e.id)
 | 
				
			||||||
 | 
								for (let i = 0; i < storyGenreIds.length; i++) {
 | 
				
			||||||
 | 
									const storyGenreId = storyGenreIds[i];
 | 
				
			||||||
 | 
									if (pubGenreIds.includes(storyGenreId)) return true
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}).map(e => e.id)
 | 
				
			||||||
 | 
							console.log("relevant pubs: ", relevantPubIds)
 | 
				
			||||||
 | 
							setRelevantPubIds(relevantPubIds)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const storiesSelectItems = stories.map((e: Story) => (
 | 
						const storiesSelectItems = stories.map((e: Story) => (
 | 
				
			||||||
		<SelectItem value={e.id?.toString()} key={e.title}>
 | 
							<SelectItem value={e.id?.toString()} key={e.title}>
 | 
				
			||||||
			{e.title}
 | 
								{e.title}
 | 
				
			||||||
		</SelectItem>
 | 
							</SelectItem>
 | 
				
			||||||
	))
 | 
						))
 | 
				
			||||||
	const pubsSelectItems = pubs.map(e => (
 | 
						const pubsSelectItems = pubs.map(e => {
 | 
				
			||||||
		<SelectItem value={e.id} key={e.title}>
 | 
							const isDisabled = !relevantPubIds.includes(e.id)
 | 
				
			||||||
			{e.title}
 | 
							return (
 | 
				
			||||||
		</SelectItem>
 | 
								<SelectItem disabled={isDisabled} value={e.id.toString()} key={e.title}>
 | 
				
			||||||
	))
 | 
									{e.title}
 | 
				
			||||||
 | 
								</SelectItem>
 | 
				
			||||||
 | 
							)
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const reponsesSelectItems = responses.map(e => (
 | 
						const reponsesSelectItems = responses.map(e => (
 | 
				
			||||||
		<SelectItem value={e.id} key={e.title}>
 | 
							<SelectItem value={e.id.toString()} key={e.response}>
 | 
				
			||||||
			{e.response}
 | 
								{e.response}
 | 
				
			||||||
		</SelectItem>
 | 
							</SelectItem>
 | 
				
			||||||
	))
 | 
						))
 | 
				
			||||||
| 
						 | 
					@ -127,7 +151,8 @@ export default function SubmissionForm({ stories, pubs, responses, defaults, clo
 | 
				
			||||||
					render={({ field }) => (
 | 
										render={({ field }) => (
 | 
				
			||||||
						<FormItem>
 | 
											<FormItem>
 | 
				
			||||||
							<FormLabel className="text-sm md:text-base">Publication</FormLabel>
 | 
												<FormLabel className="text-sm md:text-base">Publication</FormLabel>
 | 
				
			||||||
							<Select onValueChange={field.onChange} defaultValue={field.value?.toString()}>
 | 
												<Select onOpenChange={() => updateRelevantPubs(form.getValues().storyId
 | 
				
			||||||
 | 
												)} onValueChange={field.onChange} defaultValue={field.value?.toString()}>
 | 
				
			||||||
								<FormControl>
 | 
													<FormControl>
 | 
				
			||||||
									<SelectTrigger>
 | 
														<SelectTrigger>
 | 
				
			||||||
										<SelectValue placeholder="Select something">
 | 
															<SelectValue placeholder="Select something">
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue