Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@/CivicSignalBlog: Add Web Tools authentication form configuration #1009

Merged
merged 20 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
fc9db97
feat: Add authentication forms globals configuration for web-tools
m453h Nov 27, 2024
0f3fff1
Update LoginTab to include need to activate message
m453h Nov 28, 2024
93db502
Add login button label
m453h Nov 28, 2024
6a52ccb
chore: Separate auth form globals configuration
m453h Nov 29, 2024
c3430f9
feat: Add dynamic fields for Login form configurations
m453h Nov 29, 2024
473839f
feat: Add messages buttons sections for Login Form
m453h Nov 29, 2024
3e58df5
feat: Add proper validation rules for Login form input fields
m453h Dec 2, 2024
bdd585f
fix: Improve Password reset form configuration
m453h Dec 2, 2024
c303074
chore: Create formInputFields custom input
m453h Dec 2, 2024
a84aec8
feat: Implement registration form
m453h Dec 2, 2024
4676904
Update apps/civicsignalblog/src/payload/fields/formInputFields.js
m453h Dec 5, 2024
ce70f4e
chore: Remove dynamic form fields configuration
m453h Dec 5, 2024
ccb037b
Merge branch 'ft/civicsignalblog-auth_forms' of github.com:CodeForAfr…
m453h Dec 5, 2024
5daa691
Remove unused formInputFields
m453h Dec 5, 2024
13feded
chore: Fix formatting issues
m453h Dec 5, 2024
cf6deea
feat: Add default values for LoginForm configuration
m453h Dec 5, 2024
ed8517b
feat: Add default values for Registration and ResetPassword forms
m453h Dec 5, 2024
b7a2911
chore: Rename Messages tab to Form Messages
m453h Dec 5, 2024
744f28c
feat: Improve form Tab labels
m453h Dec 5, 2024
71e26a5
Merge branch 'main' into ft/civicsignalblog-auth_forms
m453h Dec 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion apps/civicsignalblog/payload.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ import Actions from "./src/payload/components/actions";
import Publication from "./src/payload/globals/Publication";
import Main from "./src/payload/globals/Site/main";
import Research from "./src/payload/globals/Site/research";
import Login from "./src/payload/globals/Forms/login";
import PasswordReset from "./src/payload/globals/Forms/resetPassword";
import Registration from "./src/payload/globals/Forms/registration";
import { applicationPages } from "./src/payload/lib/data/common/applications";
import { defaultLocale, locales } from "./src/payload/utils/locales";

Expand Down Expand Up @@ -74,7 +77,7 @@ export default buildConfig({
MediaData,
Users,
] as CollectionConfig[],
globals: [Publication, Research, Main] as GlobalConfig[],
globals: [Publication, Research, Main, Login, Registration, PasswordReset] as GlobalConfig[],
...(locales?.length
? {
localization: {
Expand Down
63 changes: 63 additions & 0 deletions apps/civicsignalblog/src/payload/fields/formInputFields.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
function formInputFields({ minRows, maxRows, validate }) {
return {
name: "fields",
type: "array",
label: "Form input fields",
minRows,
maxRows,
validate,
labels: {
singular: "Field",
plural: "Fields",
},
admin: {
className: "array-field-nested",
components: {
RowLabel: ({ data, index }) => {
let label = "";
if (data.name) {
label = data.name;
}
if (!label) {
label = `Field ${String(index).padStart(2, "0")}`;
}
return label;
},
m453h marked this conversation as resolved.
Show resolved Hide resolved
},
initCollapsed: true,
},
fields: [
{
type: "row",
fields: [
{
name: "name",
type: "text",
required: true,
},
{
name: "label",
type: "text",
required: true,
},
],
},
{
type: "row",
fields: [
{
name: "errorMessage",
type: "text",
required: true,
},
{
name: "hint",
type: "text",
},
],
},
],
};
}

export default formInputFields;
95 changes: 95 additions & 0 deletions apps/civicsignalblog/src/payload/globals/Forms/login/LoginTab.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import formInputFields from "#civicsignalblog/payload/fields/formInputFields";
import richText from "#civicsignalblog/payload/fields/richText";

const LoginTab = {
label: "Login Form",
fields: [
{
type: "collapsible",
label: "Title & Description",
fields: [
{
name: "title",
type: "text",
defaultValue: "Login",
required: true,
localized: true,
},
],
},
{
type: "collapsible",
label: "Fields",
fields: [
formInputFields({
minRows: 2,
maxRows: 2,
validate: (val, args) => {
if (val.length < args.minRows)
return `You must add ${args.minRows} form input fields`;

if (!val.some((field) => field.name === "email")) {
return "Login form must have a field with email as name";
}

if (!val.some((field) => field.name === "password")) {
return "Login form must have a field with password as name";
}
return true;
},
}),
],
},
{
type: "collapsible",
label: "Buttons",
fields: [
{
type: "row",
fields: [
{
name: "loginButton",
type: "text",
defaultValue: "Login",
required: true,
localized: true,
},
{
name: "registrationButton",
type: "text",
defaultValue: "No Account ? Register Now!",
required: true,
localized: true,
},
{
name: "forgotPasswordButton",
type: "text",
defaultValue: "Forgot your password ?",
required: true,
localized: true,
},
],
},
],
},
{
type: "collapsible",
label: "Messages",
fields: [
{
name: "loginFailed",
type: "text",
defaultValue: "Your email or password was wrong.",
required: true,
},
richText({
name: "needsToActivate",
required: true,
localized: true,
}),
],
},
],
};

export default LoginTab;
15 changes: 15 additions & 0 deletions apps/civicsignalblog/src/payload/globals/Forms/login/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import LoginTab from "./LoginTab";

import settings from "#civicsignalblog/payload/utils/createGlobalSettings";

const Login = settings({
slug: `login-form`,
label: "Login",
group: "Forms",
access: {
read: () => true,
},
tabs: [LoginTab],
});

export default Login;
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import formInputFields from "#civicsignalblog/payload/fields/formInputFields";
import richText from "#civicsignalblog/payload/fields/richText";

const RegisterTab = {
label: "Registration Form",
fields: [
{
type: "collapsible",
label: "Title & Description",
fields: [
{
name: "title",
type: "text",
defaultValue: "Sign Up",
required: true,
localized: true,
},
{
name: "description",
type: "text",
defaultValue: "Create an account to use all our tools for free.",
required: true,
localized: true,
},
],
},
{
type: "collapsible",
label: "Fields",
fields: [
formInputFields({
minRows: 5,
maxRows: 5,
validate: (val, args) => {
if (val.length < args.minRows)
return `You must add ${args.minRows} form input fields`;

const requiredFields = [
"email",
"fullname",
"password",
"confirm_password",
"notes",
"terms_of_use",
];

const missingFields = requiredFields.filter(
(fieldName) => !val.some((field) => field.name === fieldName),
);

if (missingFields.length > 0) {
return `Registration form must have fields with the following names: ${missingFields.join(", ")}`;
}

return true;
},
}),
],
},
{
type: "collapsible",
label: "Form Messages",
fields: [
{
name: "successFeedback",
type: "text",
defaultValue: "Successfully signed up.",
required: true,
localized: true,
},
{
name: "passwordsMismatch",
type: "text",
defaultValue: "Passwords do not match.",
required: true,
localized: true,
},
{
name: "passwordTooShort",
type: "text",
defaultValue: "Passwords must be at least 8 characters long..",
required: true,
localized: true,
},
richText({
name: "userAlreadyExists",
required: true,
localized: true,
}),
richText({
name: "signupSuccess",
required: true,
localized: true,
}),
],
},
{
type: "collapsible",
label: "Buttons",
fields: [
{
type: "row",
fields: [
{
name: "signUpButton",
type: "text",
defaultValue: "Sign Up",
required: true,
localized: true,
},
],
},
],
},
],
};

export default RegisterTab;
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import RegistrationTab from "./RegistrationTab";

import settings from "#civicsignalblog/payload/utils/createGlobalSettings";

const Registration = settings({
slug: `registration-form`,
label: "Registration",
group: "Forms",
access: {
read: () => true,
},
tabs: [RegistrationTab],
});

export default Registration;
Loading
Loading