mirror of
https://github.com/cssgunc/compass.git
synced 2025-04-06 20:50:17 -04:00
the heck am i doing
This commit is contained in:
parent
3e6875cffe
commit
a14a366784
|
@ -4,7 +4,6 @@
|
|||
import Button from '@/components/Button';
|
||||
import Input from '@/components/Input'
|
||||
import InlineLink from '@/components/InlineLink';
|
||||
import Paper from '@/components/auth/Paper';
|
||||
import Image from 'next/image';
|
||||
import { useState } from "react";
|
||||
import PasswordInput from '@/components/auth/PasswordInput';
|
||||
|
@ -61,7 +60,7 @@ export default function Page() {
|
|||
{emailError && <ErrorBanner heading={emailError} />}
|
||||
|
||||
<div className="mb-6">
|
||||
<PasswordInput title="Password" valid={passwordError == ""} onChange={handlePasswordChange} required />
|
||||
<PasswordInput title="Password" valid={passwordError == ""} onChange={handlePasswordChange} />
|
||||
|
||||
</div>
|
||||
{passwordError && <ErrorBanner heading={passwordError} />}
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
class CollectionImpl {
|
||||
title: string;
|
||||
icon: any;
|
||||
data: any;
|
||||
|
||||
constructor(title: string, icon: any) {
|
||||
this.title = title;
|
||||
this.icon = icon;
|
||||
}
|
||||
|
||||
// subject to change
|
||||
setData(data: any){
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
}
|
15
compass/utils/classes/Field.ts
Normal file
15
compass/utils/classes/Field.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
import { Icons } from "../constants";
|
||||
|
||||
export class Field {
|
||||
iconKey: keyof typeof Icons;
|
||||
title: string;
|
||||
|
||||
constructor(iconKey: keyof typeof Icons, title: string) {
|
||||
this.iconKey = iconKey;
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
validateInput(value: any): boolean {
|
||||
return value !== null;
|
||||
}
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
import { InputHTMLAttributes } from "react";
|
||||
import { Icons } from "../constants";
|
||||
|
||||
export type InputProps = InputHTMLAttributes<HTMLInputElement> & {
|
||||
iconKey?: keyof typeof Icons; // Use keyof typeof to ensure the key exists in Icons
|
||||
title?: string; // Assuming title is always a string
|
||||
type?: string;
|
||||
placeholder?: string;
|
||||
};
|
|
@ -29,7 +29,8 @@ export enum User {
|
|||
export enum COLLECTION {
|
||||
RESOURCE,
|
||||
SERVICE,
|
||||
USER
|
||||
USER,
|
||||
TRAINING_MANUAL
|
||||
}
|
||||
|
||||
export enum PROGRAM {
|
||||
|
@ -47,8 +48,4 @@ export enum DATATYPE {
|
|||
SELECT
|
||||
}
|
||||
|
||||
// export const COLLECTION_MAP: {[key in COLLECTION]: CollectionImpl} = {
|
||||
// [COLLECTION.RESOURCE]: new CollectionImpl('Resources', Icons.ResourceIcon),
|
||||
// [COLLECTION.SERVICE]: new CollectionImpl('Services', Icons.ServiceIcon),
|
||||
// [COLLECTION.USER]: new CollectionImpl('Users', Icons.UserIcon)
|
||||
// }
|
||||
|
39
compass/utils/implementations/CollectionDataImpl.ts
Normal file
39
compass/utils/implementations/CollectionDataImpl.ts
Normal file
|
@ -0,0 +1,39 @@
|
|||
import { Field } from "../classes/Field";
|
||||
|
||||
export class CollectionDataImpl {
|
||||
headers: Field[];
|
||||
rows: Record<string, any>[];
|
||||
|
||||
constructor(headers: Field[] = [], rows: Record<string, any>[] = []) {
|
||||
this.headers = headers;
|
||||
this.rows = rows;
|
||||
}
|
||||
|
||||
addRow(row: Record<string, any>): void {
|
||||
let isValidRow = true;
|
||||
|
||||
for (const header of this.headers) {
|
||||
const value = row[header.title];
|
||||
if (!header.validateInput(value)) {
|
||||
console.error(`Validation failed for ${header.title} with value ${value}`);
|
||||
isValidRow = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (isValidRow) {
|
||||
this.rows.push(row);
|
||||
} else {
|
||||
console.log('Row not added due to validation failure.');
|
||||
}
|
||||
}
|
||||
|
||||
getRows(): Record<string, any>[] {
|
||||
return this.rows;
|
||||
}
|
||||
|
||||
getHeaders(): Field[] {
|
||||
return this.headers;
|
||||
}
|
||||
|
||||
}
|
15
compass/utils/implementations/CollectionImpl.ts
Normal file
15
compass/utils/implementations/CollectionImpl.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
import { CollectionDataImpl } from "./CollectionDataImpl";
|
||||
|
||||
export class CollectionImpl {
|
||||
title: string;
|
||||
icon: any;
|
||||
data: CollectionDataImpl;
|
||||
|
||||
constructor(title: string, icon: any, data: CollectionDataImpl) {
|
||||
this.title = title;
|
||||
this.icon = icon;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
|
||||
}
|
18
compass/utils/implementations/FieldImpl/EmailFieldImpl.ts
Normal file
18
compass/utils/implementations/FieldImpl/EmailFieldImpl.ts
Normal file
|
@ -0,0 +1,18 @@
|
|||
import { Field } from "@/utils/classes/Field";
|
||||
|
||||
|
||||
export class EmailFieldImpl extends Field {
|
||||
|
||||
constructor() {
|
||||
super('EmailTableIcon', "Email");
|
||||
}
|
||||
|
||||
validateInput(value: any) : boolean {
|
||||
if (typeof value !== 'string') {
|
||||
return false;
|
||||
}
|
||||
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
||||
return emailRegex.test(value);
|
||||
}
|
||||
|
||||
}
|
15
compass/utils/implementations/FieldImpl/IntegerFieldImpl.ts
Normal file
15
compass/utils/implementations/FieldImpl/IntegerFieldImpl.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
import { Icons } from "@/utils/constants";
|
||||
import { Field } from "@/utils/classes/Field";
|
||||
|
||||
|
||||
export class IntegerFieldImpl extends Field {
|
||||
|
||||
constructor(title: string) {
|
||||
super('NumberTableIcon', title);
|
||||
}
|
||||
|
||||
validateInput(value: any) : boolean {
|
||||
return Number.isInteger(value);
|
||||
}
|
||||
|
||||
}
|
18
compass/utils/implementations/FieldImpl/LinkFieldImpl.ts
Normal file
18
compass/utils/implementations/FieldImpl/LinkFieldImpl.ts
Normal file
|
@ -0,0 +1,18 @@
|
|||
import { Field } from "@/utils/classes/Field";
|
||||
|
||||
|
||||
export class LinkFieldImpl extends Field {
|
||||
|
||||
constructor() {
|
||||
super('LinkTableIcon', "Link");
|
||||
}
|
||||
|
||||
validateInput(value: any) : boolean {
|
||||
if (typeof value !== 'string') {
|
||||
return false;
|
||||
}
|
||||
const urlRegex = /^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/;
|
||||
return urlRegex.test(value);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
import { Field } from "@/utils/classes/Field";
|
||||
|
||||
|
||||
export class MultiselectFieldImpl extends Field {
|
||||
|
||||
tags: Set<any>;
|
||||
selectedTags: Set<any>;
|
||||
|
||||
constructor(title: string, tags: Set<any> = new Set()) {
|
||||
super('MultiselectTableIcon', title);
|
||||
this.tags = tags
|
||||
this.selectedTags = new Set();
|
||||
}
|
||||
|
||||
getTags() {
|
||||
return this.tags
|
||||
}
|
||||
|
||||
addTag(tag: any) {
|
||||
this.tags.add(tag);
|
||||
}
|
||||
|
||||
removeTag(tag: any) {
|
||||
if (this.tags.has(tag)){
|
||||
this.tags.delete(tag);
|
||||
}
|
||||
}
|
||||
|
||||
selectTag(tag: any) {
|
||||
this.selectedTags.add(tag);
|
||||
}
|
||||
|
||||
removeSelectedTag(tag: any) {
|
||||
if (this.selectedTags.has(tag)){
|
||||
this.selectedTags.delete(tag);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
15
compass/utils/implementations/FieldImpl/StringFieldImpl.ts
Normal file
15
compass/utils/implementations/FieldImpl/StringFieldImpl.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
import { Icons } from "@/utils/constants";
|
||||
import { Field } from "@/utils/classes/Field";
|
||||
|
||||
|
||||
export class StringFieldImpl extends Field {
|
||||
|
||||
constructor(iconKey: keyof typeof Icons, title: string) {
|
||||
super(iconKey, title);
|
||||
}
|
||||
|
||||
validateInput(value: any) : boolean {
|
||||
return typeof value === 'string';
|
||||
}
|
||||
|
||||
}
|
17
compass/utils/models/CollectionData.ts
Normal file
17
compass/utils/models/CollectionData.ts
Normal file
|
@ -0,0 +1,17 @@
|
|||
import { Field } from "../classes/Field";
|
||||
import { PROGRAM } from "../constants";
|
||||
import { CollectionDataImpl } from "../implementations/CollectionDataImpl";
|
||||
import { CollectionImpl } from "../implementations/CollectionImpl";
|
||||
import { MultiselectFieldImpl } from "../implementations/FieldImpl/MultiselectFieldImpl";
|
||||
import { StringFieldImpl } from "../implementations/FieldImpl/StringFieldImpl";
|
||||
|
||||
const programSet: Set<PROGRAM> = new Set([PROGRAM.COMMUNITY_EDUCATION, PROGRAM.DOMESTIC_VIOLENCE, PROGRAM.ECONOMIC_STABILITY]);
|
||||
|
||||
export const ServiceCollectionDataType: Field[] = [new StringFieldImpl("Name"), new MultiselectFieldImpl("Status"), new StringFieldImpl("Summary"), new StringFieldImpl("Requirements"), new MultiselectFieldImpl('Program', programSet)]
|
||||
|
||||
export const ServiceCollectionData = new CollectionImpl('Service','ResourceIcon',new CollectionDataImpl(ServiceCollectionDataType))
|
||||
|
||||
export const ResourceCollectionDataType: Field[] = [new StringFieldImpl("Name"), new MultiselectFieldImpl("Status"), new StringFieldImpl("Summary"), new StringFieldImpl("Requirements"), new MultiselectFieldImpl('Program', programSet)]
|
||||
|
||||
export const ResourceCollectionData = new CollectionImpl('Service','ResourceIcon',new CollectionDataImpl(ServiceCollectionDataType))
|
||||
|
Loading…
Reference in New Issue
Block a user