-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add ability to define custom fields (#406)
* feat: allow adding custom fields * feat: add example on how to use * chore: allow input to be optional and add format * chore: fix issue with password field * chore: add changeset * fix: fix test cases * fix: e2e tests * fix: missing check to e2e * chore: change example for page router
- Loading branch information
1 parent
4e25899
commit 0c80933
Showing
17 changed files
with
202 additions
and
44 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": minor | ||
--- | ||
|
||
add ability to define custom fields in edit |
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,42 @@ | ||
"use client"; | ||
|
||
import { useState } from "react"; | ||
import type { CustomInputProps } from "@premieroctet/next-admin"; | ||
|
||
const PasswordInput = (props: CustomInputProps) => { | ||
const [changePassword, setChangePassword] = useState(false); | ||
|
||
if (props.mode === "create") { | ||
return <PasswordBaseInput {...props} />; | ||
} | ||
|
||
return ( | ||
<div className="flex flex-col items-start gap-4"> | ||
{changePassword && <PasswordBaseInput {...props} />} | ||
<button | ||
onClick={() => { | ||
setChangePassword((value) => !value); | ||
// @ts-expect-error | ||
props?.onChange({ target: { value: undefined } }); | ||
}} | ||
type="button" | ||
className="rounded-md bg-indigo-600 px-3.5 py-2.5 text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600" | ||
> | ||
{changePassword ? "Close" : "Change Password"} | ||
</button> | ||
</div> | ||
); | ||
}; | ||
|
||
const PasswordBaseInput = (props: CustomInputProps & {}) => ( | ||
<input | ||
type="password" | ||
onChange={props.onChange} | ||
name={props.name} | ||
required={props.required} | ||
value={props.value ?? ""} | ||
className="dark:bg-dark-nextadmin-background-subtle text-nextadmin-content-inverted dark:text-dark-nextadmin-content-inverted ring-nextadmin-border-default focus:ring-nextadmin-brand-default dark:focus:ring-dark-nextadmin-brand-default dark:ring-dark-nextadmin-border-strong block w-full rounded-md border-0 px-2 py-1.5 text-sm shadow-sm ring-1 ring-inset transition-colors duration-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50 sm:leading-6" | ||
/> | ||
); | ||
|
||
export default PasswordInput; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ export const dataTest: DataTest = { | |
User: { | ||
email: "[email protected]", | ||
name: "MY_USER", | ||
newPassword: "newPassword", | ||
}, | ||
Post: { | ||
title: "MY_POST", | ||
|
@@ -97,6 +98,9 @@ export const fillForm = async ( | |
case "User": | ||
await page.fill('input[id="email"]', dataTest.User.email); | ||
await page.fill('input[id="name"]', dataTest.User.name); | ||
if (await page.isVisible('input[name="newPassword"]')) { | ||
await page.fill('input[name="newPassword"]', dataTest.User.newPassword); | ||
} | ||
await page.setInputFiles('input[type="file"]', { | ||
name: "test.txt", | ||
mimeType: "text/plain", | ||
|
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
8 changes: 8 additions & 0 deletions
8
apps/example/prisma/migrations/20240907035434_add_hashed_password_field/migration.sql
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,8 @@ | ||
/* | ||
Warnings: | ||
- Added the required column `hashedPassword` to the `User` table without a default value. This is not possible if the table is not empty. | ||
*/ | ||
-- AlterTable | ||
ALTER TABLE "User" ADD COLUMN "hashedPassword" TEXT NOT NULL; |
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
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
Oops, something went wrong.