Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | import {
CouchersIcon,
EmailIcon,
GlobeIcon,
LinkedInIcon,
} from "components/Icons";
import { GetMyVolunteerInfoRes } from "proto/account_pb";
// Constants
export const LINK_TYPES = ["couchers", "email", "linkedin", "website"] as const;
export type LinkType = (typeof LINK_TYPES)[number];
// Validation patterns
export const EMAIL_PATTERN = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
export const URL_PATTERN = /^https?:\/\/.+/;
export const LINKEDIN_USERNAME_PATTERN = /^[\w-]{3,100}$/;
// Form types
export interface VolunteerFormData {
overrideName: boolean;
displayName: string;
overrideLocation: boolean;
displayLocation: string;
showOnTeamPage: boolean;
linkType: LinkType;
linkText: string;
linkUrl: string;
}
// Type guard
export function isValidLinkType(value: string): value is LinkType {
return LINK_TYPES.includes(value as LinkType);
}
// Helper functions
export function getLinkTypeIcon(linkType: string) {
switch (linkType) {
case "linkedin":
return LinkedInIcon;
case "email":
return EmailIcon;
case "couchers":
return CouchersIcon;
default:
return GlobeIcon;
}
}
// Transform API data to form defaults
export function getFormDefaultValues(
volunteerInfo?: GetMyVolunteerInfoRes.AsObject,
): VolunteerFormData {
Iif (!volunteerInfo) {
return {
overrideName: false,
displayName: "",
overrideLocation: false,
displayLocation: "",
showOnTeamPage: true,
linkType: "couchers",
linkText: "",
linkUrl: "",
};
}
const linkType =
volunteerInfo.linkType && isValidLinkType(volunteerInfo.linkType)
? volunteerInfo.linkType
: "couchers";
return {
overrideName: false,
displayName: volunteerInfo.displayName || "",
overrideLocation: false,
displayLocation: volunteerInfo.displayLocation || "",
showOnTeamPage: volunteerInfo.showOnTeamPage,
linkType,
linkText: volunteerInfo.linkText || "",
linkUrl: volunteerInfo.linkUrl || "",
};
}
|