Skip to content

Commit 68b2b10

Browse files
changed and revamped schema (#2)
* refactor: consolidate and update schema definitions, remove unused schemas * refactor: remove unused comments and clean up schema definitions * refactor: update Visitor schema to include detailed fields and replace icon * refactor: enhance Staff schema with detailed fields and add Profile schema * refactor: enhance Senate schema with detailed fields and add Profile schema * refactor: enhance Former schema with detailed fields and remove redundant Profile schema * refactor: enhance schema definitions for BoardOfGovernor, ChairPerson, Former, Senate, Staff, and Visitor with detailed profile fields * refactor: enhance About, Academics, Admission, CommonSchema, Former, and index schemas with detailed fields and remove unused linkStructure * refactor: remove Academics schema and introduce detailed CSE, ECE, and DSAI schemas with credit structures * refactor: remove individual credit schemas and consolidate into a unified Credit schema with detailed course structure * refactor: introduce CreditIdInput component for generating IDs based on faculty names * changes made
1 parent 91662de commit 68b2b10

20 files changed

+803
-408
lines changed
+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/* eslint-disable @typescript-eslint/no-unused-vars */
2+
/* eslint-disable @typescript-eslint/no-explicit-any */
3+
import { forwardRef, useEffect, useMemo } from "react";
4+
import { PatchEvent, set, StringInputProps, unset, useFormValue } from "sanity";
5+
import { TextInput } from "@sanity/ui";
6+
7+
export function generateId(input: string) {
8+
const cleanedInput = input.trim();
9+
10+
const match = cleanedInput.match(/^(MA|CS|HS|EG|PH|DS|EC)-(\d+)$/i);
11+
if (match) {
12+
const prefix = match[1].toLowerCase();
13+
const number = match[2];
14+
return `${prefix}${number}`;
15+
}
16+
17+
return "";
18+
}
19+
20+
const CreditIdInput = forwardRef<HTMLInputElement, StringInputProps>(
21+
(props, ref) => {
22+
const facultyName =
23+
(useFormValue(["content", "head", "name"]) as string) ?? "";
24+
console.log("Faculty Name:", facultyName); // Debugging
25+
26+
const idValue = useMemo(() => generateId(facultyName) || "default-id", [
27+
facultyName,
28+
]);
29+
30+
const { schemaType, elementProps, changed, focused, renderDefault, ...filteredProps } = props;
31+
32+
const { value, onChange } = props;
33+
34+
useEffect(() => {
35+
if (onChange) {
36+
if (idValue) {
37+
onChange(PatchEvent.from(set(idValue)));
38+
} else {
39+
onChange(PatchEvent.from(unset()));
40+
}
41+
}
42+
}, [idValue, onChange]);
43+
44+
return (
45+
<TextInput
46+
ref={ref}
47+
readOnly
48+
value={idValue || "Generating..."}
49+
/>
50+
);
51+
}
52+
);
53+
54+
CreditIdInput.displayName = "CreditIdInput";
55+
56+
export default CreditIdInput;

src/sanity/components/facultyIdInput.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,4 @@ const FacultyIdInput = forwardRef<HTMLInputElement, StringInputProps>(
5252

5353
FacultyIdInput.displayName = "FacultyIdInput";
5454

55-
export default FacultyIdInput;
55+
export default FacultyIdInput;

src/sanity/schemaTypes/About.ts

+103-73
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,6 @@
11
import { SearchSlashIcon } from "lucide-react";
22
import { defineField, defineType } from "sanity";
33

4-
export const directorMessage = defineType({
5-
name: "directorMessage",
6-
title: "Director Message",
7-
type: "document",
8-
fields: [
9-
defineField({
10-
name: "heading",
11-
title: "Heading",
12-
type: "string",
13-
}),
14-
defineField({
15-
name: "text1",
16-
title: "Text 1",
17-
type: "string",
18-
}),
19-
defineField({
20-
name: "text2",
21-
title: "Text 2",
22-
type: "string",
23-
}),
24-
defineField({
25-
name: "text3",
26-
title: "Text 3",
27-
type: "string",
28-
}),
29-
],
30-
});
31-
32-
export const coreValues = defineType({
33-
name: "coreValues",
34-
title: "Core Values",
35-
type: "document",
36-
fields: [
37-
defineField({
38-
name: "id",
39-
title: "ID",
40-
type: "string",
41-
}),
42-
defineField({
43-
name: "text",
44-
title: "Text",
45-
type: "string",
46-
}),
47-
],
48-
});
49-
50-
export const mission = defineType({
51-
name: "mission",
52-
title: "Mission",
53-
description: "Mission Regarding The Topic",
54-
type: "document",
55-
fields: [
56-
defineField({
57-
name: "missionText",
58-
title: "Mission Text",
59-
type: "string",
60-
}),
61-
],
62-
});
63-
64-
// Define the About Schema
654
export const About = defineType({
665
name: "about",
676
title: "About",
@@ -75,11 +14,36 @@ export const About = defineType({
7514
description: "About Text",
7615
}),
7716
defineField({
78-
name: "director",
79-
title: "Director",
80-
description: "Reference to the director profile",
81-
type: 'reference',
82-
to : [{type : 'profile'}]
17+
name: "profiles",
18+
title: "Profiles",
19+
type: "array",
20+
of: [
21+
{
22+
type: "object",
23+
fields: [
24+
defineField({
25+
name: "title",
26+
title: "Profile Title",
27+
type: "string",
28+
description: "Title of the profile",
29+
}),
30+
defineField({
31+
name: "content",
32+
title: "Content",
33+
type: "array",
34+
of: [{ type: "string" }],
35+
description: "Content of the profile",
36+
}),
37+
defineField({
38+
name: "imageURL",
39+
title: "Image URL",
40+
type: "string",
41+
description: "URL of the profile image",
42+
}),
43+
],
44+
},
45+
],
46+
description: "Profiles associated with the visitor",
8347
}),
8448
defineField({
8549
name: "briefProfile",
@@ -96,23 +60,63 @@ export const About = defineType({
9660
defineField({
9761
name: "image_prof",
9862
title: "Image Prof",
99-
description: "Reference to an image",
100-
type: "reference",
101-
to: [{ type: "img" }],
63+
description: "Image related to the topic",
64+
type: "object", // Explicitly defining it as an object
65+
fields: [
66+
defineField({
67+
name: "name",
68+
type: "string",
69+
title: "Name",
70+
description: "Name of the image",
71+
}),
72+
defineField({
73+
name: "imageURL",
74+
title: "Image URL",
75+
type: "string",
76+
description: "URL of the image",
77+
}),
78+
],
10279
}),
10380
defineField({
10481
name: "mission",
10582
title: "Mission",
10683
description: "Mission Regarding The Topic",
10784
type: "array",
108-
of: [{ type: "mission" }],
85+
of: [
86+
{
87+
type: "object",
88+
fields: [
89+
defineField({
90+
name: "missionText",
91+
title: "Mission Text",
92+
type: "string",
93+
}),
94+
],
95+
},
96+
],
10997
}),
11098
defineField({
11199
name: "coreValues",
112100
title: "Core Values",
113101
description: "Core Values Regarding The Topic",
114102
type: "array",
115-
of: [{ type: "coreValues" }],
103+
of: [
104+
{
105+
type: "object",
106+
fields: [
107+
defineField({
108+
name: "id",
109+
title: "ID",
110+
type: "string",
111+
}),
112+
defineField({
113+
name: "text",
114+
title: "Text",
115+
type: "string",
116+
}),
117+
],
118+
},
119+
],
116120
}),
117121
defineField({
118122
name: "href",
@@ -122,8 +126,34 @@ export const About = defineType({
122126
defineField({
123127
name: "directorMessage",
124128
title: "Director Message",
125-
type: "array",
126-
of: [{ type: "directorMessage" }],
129+
type: "array", // Explicitly defining it as an array of objects
130+
of: [
131+
{
132+
type: "object",
133+
fields: [
134+
defineField({
135+
name: "heading",
136+
title: "Heading",
137+
type: "string",
138+
}),
139+
defineField({
140+
name: "text1",
141+
title: "Text 1",
142+
type: "string",
143+
}),
144+
defineField({
145+
name: "text2",
146+
title: "Text 2",
147+
type: "string",
148+
}),
149+
defineField({
150+
name: "text3",
151+
title: "Text 3",
152+
type: "string",
153+
}),
154+
],
155+
},
156+
],
127157
}),
128158
],
129159
});

src/sanity/schemaTypes/Academics.ts

-58
This file was deleted.

0 commit comments

Comments
 (0)