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

Support middlewate context access in .input() #30

Merged
merged 3 commits into from
Oct 26, 2024

Conversation

chungweileong94
Copy link
Owner

What's new

  • Support middleware context access in .input(). For example:
export const sayHelloAction = serverAct
  .middleware(() => {
    const t = getTranslation('App');
    return { t };
  })
  .input(({ ctx }) =>
    zfd.formData({
      name: zfd.text(
        z
          .string({ required_error: ctx.t('error.required') })
          .max(20, { message: ctx.t('error.tooShort') }),
      ),
    }),
  )
  .formAction(async ({ formData, input, formErrors, ctx }) => {
    if (formErrors) {
      return { formData, formErrors: formErrors.formErrors.fieldErrors };
    }
    return { message: `Hello, ${input.name}!` };
  });

Copy link

stackblitz bot commented Oct 26, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link

changeset-bot bot commented Oct 26, 2024

🦋 Changeset detected

Latest commit: 40ef966

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
server-act Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@chungweileong94 chungweileong94 merged commit 7288143 into main Oct 26, 2024
3 checks passed
@chungweileong94 chungweileong94 deleted the input-ctx-access branch October 26, 2024 10:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant