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 all 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
12 changes: 11 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,14 @@ 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
55 changes: 55 additions & 0 deletions apps/civicsignalblog/src/payload/fields/formInputFieldGroup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
function formInputFieldGroup({
label,
name,
includeHintField = false,
includeErrorMessageField = true,
defaultLabelValue = "",
defaultErrorMessage = "",
defaultHint = "",
additionalFields = [],
}) {
const fields = [
{
name: `${name}Label`,
label: "Label",
type: "text",
defaultValue: defaultLabelValue,
required: true,
},
];

if (includeHintField) {
fields.push({
name: `${name}Hint`,
label: "Hint",
type: "text",
defaultValue: defaultHint,
required: true,
});
}

if (includeErrorMessageField) {
fields.push({
name: `${name}ErrorMessage`,
type: "text",
label: "Error Message",
defaultValue: defaultErrorMessage,
required: true,
});
}

fields.push(...additionalFields);

return {
type: "collapsible",
label,
fields: [
{
type: "row",
fields,
},
],
};
}

export default formInputFieldGroup;
90 changes: 90 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,90 @@
import formInputFieldGroup from "#civicsignalblog/payload/fields/formInputFieldGroup";
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: [
formInputFieldGroup({
label: "E-mail",
name: "email",
defaultLabelValue: "Email",
defaultErrorMessage: "You need to enter your email address.",
}),
formInputFieldGroup({
label: "Password",
name: "password",
defaultLabelValue: "Password",
defaultErrorMessage: "You need to enter your password.",
}),
],
},
{
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,
}),
],
},
{
type: "collapsible",
label: "Actions",
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,
},
],
},
],
},
],
};

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,146 @@
import formInputFieldGroup from "#civicsignalblog/payload/fields/formInputFieldGroup";
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: [
formInputFieldGroup({
label: "E-mail",
name: "email",
defaultLabelValue: "Email",
defaultErrorMessage: "You need to enter a valid email address.",
}),
formInputFieldGroup({
label: "Full Name",
name: "fullName",
includeErrorMessageField: false,
defaultLabelValue: "Full Name",
}),
formInputFieldGroup({
label: "Password",
name: "password",
defaultLabelValue: "Password",
defaultErrorMessage: "You need to enter your password.",
additionalFields: [
{
name: "passwordsMismatch",
type: "text",
required: true,
defaultValue: "You need to enter your password.",
localized: true,
},
{
name: "passwordTooShort",
type: "text",
required: true,
defaultValue: "Passwords must be at least 8 characters long.",
localized: true,
},
],
}),
formInputFieldGroup({
label: "Confirm Password",
name: "confirmPassword",
defaultLabelValue: "Confirm Password",
includeErrorMessageField: false,
}),
formInputFieldGroup({
label: "Notes",
name: "notes",
defaultHint:
"Tell us a little about what you want to use Media Cloud for",
defaultLabelValue: "Notes",
defaultErrorMessage:
"You have to tell us a little about why you want to use Media Cloud.",
includeHintField: true,
}),
{
type: "collapsible",
label: "Consent",
fields: [
richText({
name: "consentLabel",
label: "Label",
required: true,
localized: true,
}),
{
name: "consentError",
type: "text",
defaultValue: "You must agree to our Terms and Policies",
required: true,
localized: true,
},
],
},
],
},
{
type: "collapsible",
label: "Messages",
fields: [
{
name: "successFeedback",
type: "text",
defaultValue: "Successfully signed up.",
required: true,
localized: true,
},
richText({
name: "userAlreadyExists",
required: true,
localized: true,
}),
richText({
name: "signupSuccess",
required: true,
localized: true,
}),
],
},
{
type: "collapsible",
label: "Actions",
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