implemented #112
This commit is contained in:
@@ -11,6 +11,7 @@ import { Button } from "../../../../_components/ui/Button";
|
|||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
import dynamic from "next/dynamic";
|
import dynamic from "next/dynamic";
|
||||||
import toast from "react-hot-toast";
|
import toast from "react-hot-toast";
|
||||||
|
import { cn } from "@repo/shared-components";
|
||||||
|
|
||||||
const MarkdownEditor = dynamic(() => import("@uiw/react-md-editor"), { ssr: false });
|
const MarkdownEditor = dynamic(() => import("@uiw/react-md-editor"), { ssr: false });
|
||||||
|
|
||||||
@@ -24,6 +25,7 @@ export const ChangelogForm = ({ changelog }: { changelog?: Changelog }) => {
|
|||||||
previewImage: changelog?.previewImage || "", // Changed to accept a URL as a string
|
previewImage: changelog?.previewImage || "", // Changed to accept a URL as a string
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
const [skipUserUpdate, setSkipUserUpdate] = useState(false);
|
||||||
const [markdownText, setMarkdownText] = useState(changelog?.text || "");
|
const [markdownText, setMarkdownText] = useState(changelog?.text || "");
|
||||||
const [imageError, setImageError] = useState(false);
|
const [imageError, setImageError] = useState(false);
|
||||||
const [showImage, setShowImage] = useState(false);
|
const [showImage, setShowImage] = useState(false);
|
||||||
@@ -61,6 +63,9 @@ export const ChangelogForm = ({ changelog }: { changelog?: Changelog }) => {
|
|||||||
text: markdownText,
|
text: markdownText,
|
||||||
},
|
},
|
||||||
changelog?.id,
|
changelog?.id,
|
||||||
|
{
|
||||||
|
skipUserUpdate: skipUserUpdate,
|
||||||
|
},
|
||||||
);
|
);
|
||||||
toast.success("Daten gespeichert");
|
toast.success("Daten gespeichert");
|
||||||
if (!changelog) redirect(`/admin/changelog`);
|
if (!changelog) redirect(`/admin/changelog`);
|
||||||
@@ -96,6 +101,7 @@ export const ChangelogForm = ({ changelog }: { changelog?: Changelog }) => {
|
|||||||
{(() => {
|
{(() => {
|
||||||
if (showImage && isValidImageUrl(previewImage) && !imageError) {
|
if (showImage && isValidImageUrl(previewImage) && !imageError) {
|
||||||
return (
|
return (
|
||||||
|
// eslint-disable-next-line @next/next/no-img-element
|
||||||
<img
|
<img
|
||||||
src={previewImage}
|
src={previewImage}
|
||||||
alt="Preview"
|
alt="Preview"
|
||||||
@@ -127,6 +133,19 @@ export const ChangelogForm = ({ changelog }: { changelog?: Changelog }) => {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="card bg-base-200 col-span-6 shadow-xl">
|
<div className="card bg-base-200 col-span-6 shadow-xl">
|
||||||
|
{!changelog?.id && (
|
||||||
|
<label className="label mx-6 mt-6 w-full cursor-pointer">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
className={cn("toggle")}
|
||||||
|
checked={skipUserUpdate}
|
||||||
|
onChange={(e) => setSkipUserUpdate(e.target.checked)}
|
||||||
|
/>
|
||||||
|
<span className={cn("label-text w-full text-left")}>
|
||||||
|
Kein Popup für Nutzer für dieses Update anzeigen
|
||||||
|
</span>
|
||||||
|
</label>
|
||||||
|
)}
|
||||||
<div className="card-body">
|
<div className="card-body">
|
||||||
<div className="flex w-full gap-4">
|
<div className="flex w-full gap-4">
|
||||||
<Button
|
<Button
|
||||||
|
|||||||
@@ -4,6 +4,9 @@ import { prisma, Prisma, Changelog } from "@repo/db";
|
|||||||
export const upsertChangelog = async (
|
export const upsertChangelog = async (
|
||||||
changelog: Prisma.ChangelogCreateInput,
|
changelog: Prisma.ChangelogCreateInput,
|
||||||
id?: Changelog["id"],
|
id?: Changelog["id"],
|
||||||
|
options?: {
|
||||||
|
skipUserUpdate?: boolean;
|
||||||
|
},
|
||||||
) => {
|
) => {
|
||||||
const newChangelog = id
|
const newChangelog = id
|
||||||
? await prisma.changelog.update({
|
? await prisma.changelog.update({
|
||||||
@@ -12,10 +15,13 @@ export const upsertChangelog = async (
|
|||||||
})
|
})
|
||||||
: await prisma.$transaction(async (prisma) => {
|
: await prisma.$transaction(async (prisma) => {
|
||||||
const createdChangelog = await prisma.changelog.create({ data: changelog });
|
const createdChangelog = await prisma.changelog.create({ data: changelog });
|
||||||
|
if (!options?.skipUserUpdate) {
|
||||||
|
// Update all users to acknowledge the new changelog
|
||||||
|
|
||||||
await prisma.user.updateMany({
|
await prisma.user.updateMany({
|
||||||
data: { changelogAck: false },
|
data: { changelogAck: false },
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return createdChangelog;
|
return createdChangelog;
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user