68 lines
2.0 KiB
TypeScript
68 lines
2.0 KiB
TypeScript
/**
|
|
* SponsorSignupCommandModel
|
|
*
|
|
* UX-only model for managing sponsor signup state.
|
|
*/
|
|
|
|
export interface SponsorSignupFormData {
|
|
companyName: string;
|
|
contactEmail: string;
|
|
websiteUrl?: string;
|
|
industry?: string;
|
|
}
|
|
|
|
export interface SponsorSignupValidationErrors {
|
|
companyName?: string;
|
|
contactEmail?: string;
|
|
websiteUrl?: string;
|
|
}
|
|
|
|
export class SponsorSignupCommandModel {
|
|
private _companyName: string;
|
|
private _contactEmail: string;
|
|
private _websiteUrl: string;
|
|
private _industry: string;
|
|
|
|
constructor(initial: Partial<SponsorSignupFormData> = {}) {
|
|
this._companyName = initial.companyName || '';
|
|
this._contactEmail = initial.contactEmail || '';
|
|
this._websiteUrl = initial.websiteUrl || '';
|
|
this._industry = initial.industry || '';
|
|
}
|
|
|
|
get companyName(): string { return this._companyName; }
|
|
set companyName(value: string) { this._companyName = value; }
|
|
|
|
get contactEmail(): string { return this._contactEmail; }
|
|
set contactEmail(value: string) { this._contactEmail = value; }
|
|
|
|
get websiteUrl(): string { return this._websiteUrl; }
|
|
set websiteUrl(value: string) { this._websiteUrl = value; }
|
|
|
|
get industry(): string { return this._industry; }
|
|
set industry(value: string) { this._industry = value; }
|
|
|
|
validate(): SponsorSignupValidationErrors {
|
|
const errors: SponsorSignupValidationErrors = {};
|
|
if (!this._companyName.trim()) errors.companyName = 'Company name is required';
|
|
if (!this._contactEmail.trim()) {
|
|
errors.contactEmail = 'Contact email is required';
|
|
} else if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(this._contactEmail)) {
|
|
errors.contactEmail = 'Invalid email format';
|
|
}
|
|
if (this._websiteUrl && !this._websiteUrl.startsWith('http')) {
|
|
errors.websiteUrl = 'Website URL must start with http:// or https://';
|
|
}
|
|
return errors;
|
|
}
|
|
|
|
toCommand(): SponsorSignupFormData {
|
|
return {
|
|
companyName: this._companyName,
|
|
contactEmail: this._contactEmail,
|
|
websiteUrl: this._websiteUrl,
|
|
industry: this._industry,
|
|
};
|
|
}
|
|
}
|