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

We should make at least one of defaultPlaceholder and placeholder required. ... #7484

Closed
github-actions bot opened this issue Mar 2, 2023 · 1 comment
Labels
🙋🏻‍♂️help wanted Help from the community is appreciated

Comments

@github-actions
Copy link
Contributor

github-actions bot commented Mar 2, 2023

// TODO: We should make at least one of `defaultPlaceholder` and `placeholder` required. Do the same for label.

import { z } from "zod";

const fieldTypeEnum = z.enum([
  "name",
  "text",
  "textarea",
  "number",
  "email",
  "phone",
  "address",
  "multiemail",
  "select",
  "multiselect",
  "checkbox",
  "radio",
  "radioInput",
  "boolean",
]);

export const EditableSchema = z.enum([
  "system", // Can't be deleted, can't be hidden, name can't be edited, can't be marked optional
  "system-but-optional", // Can't be deleted. Name can't be edited. But can be hidden or be marked optional
  "user", // Fully editable
  "user-readonly", // All fields are readOnly.
]);

const fieldSchema = z.object({
  name: z.string(),
  // TODO: We should make at least one of `defaultPlaceholder` and `placeholder` required. Do the same for label.
  label: z.string().optional(),
  placeholder: z.string().optional(),

  /**
   * Supports translation
   */
  defaultLabel: z.string().optional(),
  defaultPlaceholder: z.string().optional(),

  type: fieldTypeEnum,
  options: z.array(z.object({ label: z.string(), value: z.string() })).optional(),
  optionsInputs: z
    .record(
      z.object({
        // Support all types as needed
        // Must be a subset of `fieldTypeEnum`.TODO: Enforce it in TypeScript
        type: z.enum(["address", "phone", "text"]),
        required: z.boolean().optional(),
        placeholder: z.string().optional(),
      })
    )
    .optional(),

  required: z.boolean().default(false).optional(),
  hidden: z.boolean().optional(),
  editable: z
    .enum([
      "system", // Can't be deleted, can't be hidden, name can't be edited, can't be marked optional
      "system-but-optional", // Can't be deleted. Name can't be edited. But can be hidden or be marked optional
      "user", // Fully editable
      "user-readonly", // All fields are readOnly.
    ])
    .default("user")
    .optional(),
  sources: z
    .array(
      z.object({
        // Unique ID for the `type`. If type is workflow, it's the workflow ID
        id: z.string(),
        type: z.union([z.literal("user"), z.literal("system"), z.string()]),
        label: z.string(),
        editUrl: z.string().optional(),
        // Mark if a field is required by this source or not. This allows us to set `field.required` based on all the sources' fieldRequired value
        fieldRequired: z.boolean().optional(),
      })
    )
    .optional(),
});

export const fieldsSchema = z.array(fieldSchema);
@github-actions github-actions bot added todo 🙋🏻‍♂️help wanted Help from the community is appreciated labels Mar 2, 2023
@laxmikanta415
Copy link

Is there a reason why we need to make one field required ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🙋🏻‍♂️help wanted Help from the community is appreciated
Projects
None yet
Development

No branches or pull requests

2 participants