-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add refresh on dialog client and add options on example (#448)
- Loading branch information
Showing
8 changed files
with
143 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@premieroctet/next-admin": patch | ||
--- | ||
|
||
add refresh on dialog action |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
"use server"; | ||
import { prisma } from "./../prisma"; | ||
|
||
const addTag = async (tag: string, selectedIds?: number[]) => { | ||
await prisma.post.updateMany({ | ||
where: { | ||
id: { | ||
in: selectedIds, | ||
}, | ||
}, | ||
data: { | ||
tags: { | ||
push: tag, | ||
}, | ||
}, | ||
}); | ||
}; | ||
|
||
export default addTag; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
"use client"; | ||
import { ClientActionDialogContentProps } from "@premieroctet/next-admin"; | ||
import { BaseInput, Button } from "@premieroctet/next-admin/components"; | ||
import { useState } from "react"; | ||
import addTag from "../actions/addTag"; | ||
|
||
type Props = ClientActionDialogContentProps<"User">; | ||
|
||
const AddTagDialog = ({ data, onClose }: Props) => { | ||
const [tag, setTag] = useState(""); | ||
const [isPending, setIsPending] = useState(false); | ||
|
||
const handleSubmit = () => { | ||
setIsPending(true); | ||
addTag( | ||
tag, | ||
data?.map((d) => d.id) | ||
) | ||
.then(() => { | ||
onClose?.({ | ||
type: "success", | ||
message: "Tag added successfully", | ||
}); | ||
|
||
}) | ||
.catch((e) => { | ||
console.error(e); | ||
onClose?.({ | ||
type: "error", | ||
message: "An error occured", | ||
}); | ||
}) | ||
.finally(() => { | ||
setIsPending(false); | ||
}); | ||
}; | ||
|
||
return ( | ||
<div className="flex flex-col gap-4"> | ||
<form className="flex flex-col gap-4"> | ||
<div className="text-nextadmin-content-subtle dark:text-dark-nextadmin-content-subtle text-lg font-semibold"> | ||
Add a new tag | ||
</div> | ||
<BaseInput | ||
type="text" | ||
placeholder="Tag name" | ||
className="col-span-4 row-start-3 md:col-span-2" | ||
value={tag} | ||
onChange={(e) => setTag(e.target.value)} | ||
/> | ||
</form> | ||
|
||
<div className="flex justify-between"> | ||
<Button variant="primary" onClick={() => onClose?.()}> | ||
Close | ||
</Button> | ||
<Button variant="default" loading={isPending} onClick={handleSubmit}> | ||
Add Tag | ||
</Button> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default AddTagDialog; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters