-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into jakubkarbowski/sc-25514/for-investigation-sp…
…lit-nameguard-code-into
- Loading branch information
Showing
5 changed files
with
46 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export interface ContactFormDataProps { | ||
name: string; | ||
email: string; | ||
telegram: string; | ||
message: string; | ||
source: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import * as Yup from "yup"; | ||
import { ContactFormDataProps } from "./types"; | ||
|
||
// Validation function | ||
export async function validateContactFormData( | ||
data: ContactFormDataProps, | ||
): Promise<Yup.ValidationError | null> { | ||
try { | ||
await contactFormSchema.validate(data, { abortEarly: false }); | ||
return null; // No errors, return null | ||
} catch (error) { | ||
if (error instanceof Yup.ValidationError) { | ||
return error; // Return the validation error | ||
} | ||
throw error; // Rethrow other types of errors | ||
} | ||
} | ||
|
||
export const contactFormSchema = Yup.object().shape({ | ||
name: Yup.string().required("Name is required"), | ||
email: Yup.string() | ||
.email("Invalid email format") | ||
.required("Email is required"), | ||
telegram: Yup.string() | ||
.matches(/^$|^[A-Za-z0-9_]+$/, "Invalid Telegram username") | ||
.optional(), | ||
message: Yup.string().required("Message is required"), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
import "./styles.css"; | ||
|
||
export * as Metadata from "./metadata"; | ||
export { ContactUsForm } from "./contact-form"; | ||
|
||
export { ContactUsForm } from "./contact-form/contact-form"; | ||
export { validateContactFormData } from "./contact-form/validation"; | ||
export { type ContactFormDataProps } from "./contact-form/types"; |