@verifiedinc-public/shared-ui-elements 0.14.5-beta.6 → 1.0.1-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,3 @@
1
1
  import * as zod from 'zod';
2
2
  export declare const USDateSchema: zod.ZodEffects<zod.ZodString, string, string>;
3
+ export declare const getDateSchemaWithPastValidation: (message: string) => zod.ZodEffects<zod.ZodDate, Date, Date>;
@@ -1,4 +1,3 @@
1
- export * from './birthDate.schema';
2
1
  export * from './date.schema';
3
2
  export * from './description.schema';
4
3
  export * from './email.schema';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@verifiedinc-public/shared-ui-elements",
3
- "version": "0.14.5-beta.6",
3
+ "version": "1.0.1-beta.0",
4
4
  "description": "A set of UI components, utilities that is shareable with the core apps.",
5
5
  "private": false,
6
6
  "keywords": [],
@@ -1,9 +1,9 @@
1
- import { Autocomplete, AutocompleteProps } from '@mui/material';
2
- import { useState } from 'react';
3
1
  import {
2
+ Autocomplete,
4
3
  TextField,
5
4
  type TextFieldProps as InternalFieldProps,
6
5
  } from '@mui/material';
6
+ import { useState } from 'react';
7
7
  import { inputStyle } from './styles/input';
8
8
 
9
9
  interface TextFieldProps extends Omit<InternalFieldProps, 'onChange'> {}
@@ -8,3 +8,11 @@ export const USDateSchema = zod.string().refine((value: string) => {
8
8
  }
9
9
  return false;
10
10
  }, 'Date is invalid');
11
+
12
+ export const getDateSchemaWithPastValidation = (
13
+ message: string,
14
+ ): zod.ZodEffects<zod.ZodDate, Date, Date> => {
15
+ return zod.date().refine((date) => date.getTime() < Date.now(), {
16
+ message,
17
+ });
18
+ };
@@ -1,4 +1,3 @@
1
- export * from './birthDate.schema';
2
1
  export * from './date.schema';
3
2
  export * from './description.schema';
4
3
  export * from './email.schema';
@@ -1,5 +0,0 @@
1
- import * as zod from 'zod';
2
- export declare const birthDateSchema: zod.ZodEffects<zod.ZodString, string, string>;
3
- export declare const birthDateSchemaWithPastOnlyValidation: zod.ZodEffects<zod.ZodDate, Date, Date>;
4
- export declare const simpleBirthDateSchema: zod.ZodEffects<zod.ZodString, string, string>;
5
- export declare const shortenBirthDateSchema: zod.ZodEffects<zod.ZodString, string, string>;
@@ -1,60 +0,0 @@
1
- import * as zod from 'zod';
2
-
3
- const validate = (value: string) => {
4
- const now = new Date();
5
- const minDate = new Date('1900-01-01');
6
- const maxDate = new Date(
7
- now.getFullYear(),
8
- now.getMonth(),
9
- now.getDate(),
10
- 23,
11
- 59,
12
- 59,
13
- 999,
14
- );
15
- // Safari doesn't allow date strings with hyphens
16
- const formattedValue = value.replace(/-/g, '/');
17
- const valueDate = new Date(formattedValue);
18
-
19
- if (valueDate >= minDate && valueDate <= maxDate) {
20
- const date = Date.parse(String(new Date(formattedValue)));
21
- return !isNaN(date);
22
- }
23
-
24
- return false;
25
- };
26
-
27
- export const birthDateSchema = zod.string().refine((value: string) => {
28
- const regex = /\d{2}-\d{2}-\d{4}/;
29
- if (regex.test(value)) {
30
- return validate(value);
31
- }
32
- return false;
33
- }, 'Date of Birth is invalid');
34
-
35
- export const birthDateSchemaWithPastOnlyValidation = zod.z
36
- .date()
37
- .refine((date) => date.getTime() < Date.now(), {
38
- message: 'Birthday must be in the past',
39
- });
40
-
41
- export const simpleBirthDateSchema = zod.string().refine((value: string) => {
42
- const regex = /^\d{2}\d{2}\d{4}$/;
43
- if (regex.test(value)) {
44
- const formattedValue = `${value.slice(0, 2)}/${value.slice(
45
- 2,
46
- 4,
47
- )}/${value.slice(4, 8)}`;
48
- return validate(formattedValue);
49
- }
50
- return false;
51
- }, 'Date of Birth is invalid');
52
-
53
- export const shortenBirthDateSchema = zod.string().refine((value: string) => {
54
- const regex = /^\d{2}\d{2}$/;
55
- if (regex.test(value)) {
56
- const formattedValue = `${value.slice(0, 2)}/${value.slice(2, 4)}/1970`;
57
- return validate(formattedValue);
58
- }
59
- return false;
60
- }, 'Date of Birth is invalid');