-
Notifications
You must be signed in to change notification settings - Fork 215
Add LoginForm Component for User Authentication #2763
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
base: develop
Are you sure you want to change the base?
Conversation
WalkthroughA new Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant LoginForm
participant Server
User->>LoginForm: Enter username & password, click Login
LoginForm->>Server: POST credentials via AJAX
Server-->>LoginForm: Respond with success or error
alt Success
LoginForm->>User: Call onLoginSuccess callback
else Error
LoginForm->>User: Display error message
end
User->>LoginForm: Click Create Account (optional)
LoginForm->>User: Call onCreateAccount callback
Assessment against linked issues
Assessment against linked issues: Out-of-scope changes
Suggested labels
Suggested reviewers
Poem
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
npm error Exit handler never called! ✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🧹 Nitpick comments (3)
src/components/LoginForm.tsx (2)
120-170
: Internationalization domain inconsistency
Most strings use the'dokan-lite'
text-domain, but the placeholders for username/password use'dokan'
. Mixing domains makes translation generation harder.- placeholder: __( 'Write your username', 'dokan' ), + placeholder: __( 'Write your username', 'dokan-lite' ), ... - placeholder: __( 'Write your password', 'dokan' ), + placeholder: __( 'Write your password', 'dokan-lite' ),
184-201
: Accessibility: addtype="submit"
&form
semantics
The buttons live outside any<form>
element, so keyboard “Enter” submission won’t work and screen-reader form semantics are lost. Consider wrapping inputs in a<form>
and turning the login button intotype="submit"
with a handler ononSubmit
.docs/frontend/components.md (1)
920-933
: Minor wording – “scripts dependency” → “script dependency”
Consider singular form for grammatical correctness: “include thedokan-react-components
as a script dependency”.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
docs/frontend/components.md
(17 hunks)src/components/LoginForm.tsx
(1 hunks)src/components/index.tsx
(1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
src/components/LoginForm.tsx
[error] 67-67: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
🪛 LanguageTool
docs/frontend/components.md
[uncategorized] ~70-~70: You might be missing the article “a” here.
Context: ...include the dokan-react-components
as scripts dependency and the @dokan/components
...
(AI_EN_LECTOR_MISSING_DETERMINER_A)
⏰ Context from checks skipped due to timeout of 90000ms (4)
- GitHub Check: e2e tests (1, 3)
- GitHub Check: e2e tests (2, 3)
- GitHub Check: api tests (1, 1)
- GitHub Check: e2e tests (3, 3)
🔇 Additional comments (2)
src/components/LoginForm.tsx (1)
67-77
: Minor: can use optional chaining to simplify null-checks
Static-analysis flagged this; replacing the explicitresponse &&
check withresponse?.success
is cleaner and eliminates one level of nesting.-if ( response && response.success ) { +if ( response?.success ) {[ suggest_nitpick ]
docs/frontend/components.md (1)
884-906
: Import in example does not exist in public API
import {LoginForm} from '@dokan/components';
will fail because onlyDokanLoginForm
is exported. Sync the example with the actual export name or add the additional export as noted inindex.tsx
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (6)
docs/frontend/components.md (6)
5-6
: Consistent Markdown formatting for generic termsSuggest removing backticks around generic terms and version names for clarity and consistency:
- `Dokan` provides a set of reusable `components` that can be used across both `Free` and `Pro` versions. + Dokan provides a set of reusable components that can be used across both Free and Pro versions.
26-27
: Improve grammar and clarity in dependency instructionConsider updating phrasing for readability and proper article usage:
- For both `Dokan Free and Pro` versions, we must register the `dokan-react-components` dependency when using `global` components. + For both the Free and Pro versions of Dokan, register the `dokan-react-components` dependency when using global components.
68-68
: Include LoginForm in import exampleTo showcase the new component, include
LoginForm
in the import statement:-import {DataViews, DokanBadge, DokanButton, DokanAlert, DokanLink, DokanMaskInput} from '@dokan/components'; +import {DataViews, DokanBadge, DokanButton, DokanAlert, DokanLink, DokanMaskInput, LoginForm} from '@dokan/components';
71-73
: Consistent formatting for external plugin instructionsThe sentence structure and backtick usage can be streamlined:
- For external `plugins`, we must include the `dokan-react-components` as scripts dependency and the `@dokan/components` - should be introduced as an external resource configuration to resolve the path via `webpack`: + For external plugins, include `dokan-react-components` as a script dependency and configure `@dokan/components` as an external resource in your webpack settings:
76-78
: Fix code block formatting for externals configurationThe key and colon should be on the same line for valid JavaScript syntax:
- '@dokan/components' -: - 'dokan.components', + '@dokan/components': 'dokan.components',
113-114
: Enhance clarity in export instructionConsider rephrasing for smoother flow and accurate naming:
- **Finally,** we need to export the new `component` from the `src/components/index.tsx` file. Then, we can import the new - component from `@dokan/components` in `dokan pro` version. + Finally, export the new LoginForm from `src/components/index.tsx`, then import it via `@dokan/components` in the Dokan Pro version.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
docs/frontend/components.md
(19 hunks)
🧰 Additional context used
🪛 LanguageTool
docs/frontend/components.md
[uncategorized] ~71-~71: You might be missing the article “a” here.
Context: ...include the dokan-react-components
as scripts dependency and the @dokan/components
...
(AI_EN_LECTOR_MISSING_DETERMINER_A)
⏰ Context from checks skipped due to timeout of 90000ms (4)
- GitHub Check: e2e tests (2, 3)
- GitHub Check: api tests (1, 1)
- GitHub Check: e2e tests (3, 3)
- GitHub Check: e2e tests (1, 3)
🔇 Additional comments (3)
docs/frontend/components.md (3)
22-22
: Approve addition of LoginForm to component listThe new LoginForm entry correctly adds the login form component to the available components list.
101-101
: Verify component file path in documentationEnsure that
src/components/LoginForm.tsx
exists in the codebase with the correct filename and casing.#!/bin/bash # Check for LoginForm component file fd --max-depth 3 LoginForm.tsx src/components
117-127
: Let’s locate the actualindex.tsx
and search for anyLoginForm
export:#!/bin/bash # 1. Find all index.tsx files in the repo find . -type f -name "index.tsx" # 2. Search across the repo for any export or reference to LoginForm grep -R "LoginForm" -n .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
🧹 Nitpick comments (3)
docs/frontend/components.md (3)
5-6
: Consistency: unify backtick usage for "components"
The term “components” is backticked on line 5 but not on line 6; consider removing the backticks around both instances or applying them consistently throughout this section.
26-27
: Grammar: clarify article usage for dependency registration
Rephrase to “we must register thedokan-react-components
dependency when using global components” to remove the extra article and improve readability.
79-80
: Grammar: clarify script vs dependency phrasing
Consider rephrasing to “includedokan-react-components
as a script dependency and configure@dokan/components
as an external resource” for clearer intent.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
docs/frontend/components.md
(19 hunks)
🧰 Additional context used
🪛 LanguageTool
docs/frontend/components.md
[uncategorized] ~79-~79: You might be missing the article “a” here.
Context: ...include the dokan-react-components
as scripts dependency and the @dokan/components
...
(AI_EN_LECTOR_MISSING_DETERMINER_A)
🔇 Additional comments (1)
docs/frontend/components.md (1)
109-109
: File structure: confirm LoginForm path
The tree showsLoginForm.tsx
; please verify that this matches the actual file path (including casing and directory name) to prevent broken links in docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
♻️ Duplicate comments (2)
src/components/LoginForm.tsx (2)
24-29
: Add TypeScript interface for component props.The component still lacks a typed Props interface, as previously noted. This prevents TypeScript from providing proper type checking and IDE support.
Define the interface above the component:
+interface LoginFormProps { + onLoginSuccess?: () => void; + onCreateAccount?: () => void; + createAccountLabel?: string; + loginButtonLabel?: string; +} + -const LoginForm = ( { +const LoginForm: React.FC<LoginFormProps> = ( {
41-100
: Remove unnecessaryasync
keyword or properly handle the Promise.The
onUserLogin
function is declaredasync
but doesn't useawait
, making it misleading and causing it to returnundefined
immediately.Since you're using jQuery.ajax (which doesn't return a Promise), either remove
async
:-const onUserLogin = async () => { +const onUserLogin = () => {Or if you want proper async handling, wrap the jQuery call in a Promise:
const onUserLogin = async () => { // ... existing setup code ... - $.ajax({ + await new Promise((resolve, reject) => { + $.ajax({ // ... existing ajax config ... + success: (response) => { + // ... existing success logic ... + resolve(response); + }, + error: (err) => { + // ... existing error logic ... + reject(err); + }, + }); + }); - } catch ( err: any ) { - // This catch block is unreachable with current implementation - }
🧹 Nitpick comments (3)
src/components/LoginForm.tsx (3)
67-67
: Use optional chaining for cleaner conditional checks.Replace the logical AND with optional chaining for better readability and safety.
-if ( response && response.success ) { +if ( response?.success ) {
64-88
: Improve error handling consistency.The error handling in success and error callbacks could be more robust and consistent.
Consider extracting error handling logic:
+const handleError = (errorMessage: string) => { + setIsLoading(false); + setError(errorMessage); +}; +const getErrorMessage = (response: any, fallback: string) => { + return response?.data?.message || fallback; +}; success( response: any ) { setIsLoading( false ); if ( response?.success ) { onLoginSuccess(); } else { - setError( - response.data?.message || - __( - 'Failed to login. Please try again later.', - 'dokan-lite' - ) - ); + handleError( + getErrorMessage(response, __('Failed to login. Please try again later.', 'dokan-lite')) + ); } }, error( err: any ) { - setIsLoading( false ); - setError( - err.responseJSON?.data?.message || - __( - 'Failed to login. Please try again later.', - 'dokan-lite' - ) - ); + handleError( + getErrorMessage(err.responseJSON, __('Failed to login. Please try again later.', 'dokan-lite')) + ); },
133-133
: Inconsistent i18n domain usage.The placeholders use
'dokan'
while other strings use'dokan-lite'
. This inconsistency could cause translation issues.-placeholder: __( 'Write your username', 'dokan' ), +placeholder: __( 'Write your username', 'dokan-lite' ), -placeholder: __( 'Write your password', 'dokan' ), +placeholder: __( 'Write your password', 'dokan-lite' ),Also applies to: 158-158
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
docs/frontend/components.md
(5 hunks)src/components/LoginForm.tsx
(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- docs/frontend/components.md
🧰 Additional context used
🪛 Biome (1.9.4)
src/components/LoginForm.tsx
[error] 67-67: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
⏰ Context from checks skipped due to timeout of 90000ms (4)
- GitHub Check: api tests (1, 1)
- GitHub Check: e2e tests (3, 3)
- GitHub Check: e2e tests (1, 3)
- GitHub Check: e2e tests (2, 3)
🔇 Additional comments (1)
src/components/LoginForm.tsx (1)
115-212
: LGTM: Well-structured component UI with extensibility.The component structure is well-designed with proper slot integration for extensibility, appropriate state management, and good UX considerations like disabled states and loading indicators.
} catch ( err: any ) { | ||
setIsLoading( false ); | ||
setError( | ||
err.message || | ||
__( | ||
'Failed to login. Please try again later.', | ||
'dokan-lite' | ||
) | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Remove unreachable catch block.
The try-catch
block is misleading since $.ajax()
doesn't throw exceptions - it uses callback-based error handling. This catch block will never execute.
- } catch ( err: any ) {
- setIsLoading( false );
- setError(
- err.message ||
- __(
- 'Failed to login. Please try again later.',
- 'dokan-lite'
- )
- );
- }
If you implement the Promise-based approach suggested above, then this catch block would be meaningful.
Committable suggestion skipped: line range outside the PR's diff.
🤖 Prompt for AI Agents
In src/components/LoginForm.tsx around lines 90 to 99, the catch block is
unreachable because $.ajax() uses callbacks and does not throw exceptions. To
fix this, refactor the AJAX call to use a Promise-based approach (e.g., wrapping
$.ajax in a Promise or using fetch) so that errors can be caught in the catch
block. Then keep the catch block to handle errors properly; otherwise, remove
the catch block entirely.
We need to test again after the upcoming fixes. Currently, there's an issue with the UI due to changes at the component level from development. |
CC: @mrabbani Need to merge different related PRO PRs to test the PR. As far as @mralaminahamed is concerned, we should proceed to resolve the initial branch conflict for testing this PR |
All Submissions:
Changes proposed in this Pull Request:
This PR introduces a new reusable
LoginForm
component to the Dokan components library. The component provides a standardized, secure way to handle user authentication across various parts of the Dokan ecosystem.Key Features Added:
Technical Implementation:
@wordpress/element
for state managementRelated Pull Request(s)
Closes
How to test the changes in this Pull Request:
Basic Functionality Test:
Validation Test:
Customization Test:
Slot Integration Test:
Changelog entry
Title: Add LoginForm Component for Standardized User Authentication
Detailed Description:
Added a new reusable LoginForm component that provides consistent user authentication functionality across the Dokan ecosystem. The component includes form validation, error handling, and customizable callbacks for login success and account creation actions. Previous behavior required developers to implement authentication forms manually. This component standardizes the authentication experience with proper WordPress integration, security measures, and extensibility through the WordPress slot system.
Before Changes
Issue:
Screenshot:
No existing LoginForm component - developers used custom implementations
After Changes
Solution:
@dokan/components
Key Benefits:
Feature Video (optional)
To be added if needed for demonstration
PR Self Review Checklist:
Additional Notes:
FOR PR REVIEWER ONLY:
Summary by CodeRabbit