Added congregation table and field
This commit is contained in:
@ -19,34 +19,6 @@ import { useSession } from "next-auth/react"
|
||||
|
||||
// import { Tabs, List } from 'tw-elements'
|
||||
|
||||
// model Publisher {
|
||||
// id String @id @default(cuid())
|
||||
// firstName String
|
||||
// lastName String
|
||||
// email String @unique
|
||||
// phone String?
|
||||
// isActive Boolean @default(true)
|
||||
// isImported Boolean @default(false)
|
||||
// age Int?
|
||||
// availabilities Availability[]
|
||||
// assignments Assignment[]
|
||||
|
||||
// emailVerified DateTime?
|
||||
// accounts Account[]
|
||||
// sessions Session[]
|
||||
// role UserRole @default(USER)
|
||||
// desiredShiftsPerMonth Int @default(4)
|
||||
// isMale Boolean @default(true)
|
||||
// isNameForeign Boolean @default(false)
|
||||
|
||||
// familyHeadId String? // Optional familyHeadId for each family member
|
||||
// familyHead Publisher? @relation("FamilyMember", fields: [familyHeadId], references: [id])
|
||||
// familyMembers Publisher[] @relation("FamilyMember")
|
||||
// type PublisherType @default(Publisher)
|
||||
// Town String?
|
||||
// Comments String?
|
||||
// }
|
||||
|
||||
Array.prototype.groupBy = function (prop) {
|
||||
return this.reduce(function (groups, item) {
|
||||
const val = item[prop]
|
||||
@ -59,9 +31,11 @@ Array.prototype.groupBy = function (prop) {
|
||||
export default function PublisherForm({ item, me }) {
|
||||
const router = useRouter();
|
||||
const { data: session } = useSession()
|
||||
const [congregations, setCongregations] = useState([]);
|
||||
|
||||
const urls = {
|
||||
apiUrl: "/api/data/publishers/",
|
||||
congregationsUrl: "/api/data/congregations",
|
||||
indexUrl: session?.user?.role == UserRole.ADMIN ? "/cart/publishers" : "/dash"
|
||||
}
|
||||
console.log("urls.indexUrl: " + urls.indexUrl);
|
||||
@ -72,6 +46,9 @@ export default function PublisherForm({ item, me }) {
|
||||
const h = (await import("../../src/helpers/const.js")).default;
|
||||
//console.log("fetchModules: " + JSON.stringify(h));
|
||||
setHelper(h);
|
||||
|
||||
const response = await axiosInstance.get(urls.congregationsUrl);
|
||||
setCongregations(response.data);
|
||||
}
|
||||
useEffect(() => {
|
||||
fetchModules();
|
||||
@ -113,15 +90,17 @@ export default function PublisherForm({ item, me }) {
|
||||
publisher.availabilities = undefined;
|
||||
publisher.assignments = undefined;
|
||||
|
||||
let { familyHeadId, userId, ...rest } = publisher;
|
||||
let { familyHeadId, userId, congregationId, ...rest } = publisher;
|
||||
// Set the familyHead relation based on the selected head
|
||||
const familyHeadRelation = familyHeadId ? { connect: { id: familyHeadId } } : { disconnect: true };
|
||||
const userRel = userId ? { connect: { id: userId } } : { disconnect: true };
|
||||
const congregationRel = congregationId ? { connect: { id: parseInt(congregationId) } } : { disconnect: true };
|
||||
// Return the new state without familyHeadId and with the correct familyHead relation
|
||||
rest = {
|
||||
...rest,
|
||||
familyHead: familyHeadRelation,
|
||||
user: userRel
|
||||
user: userRel,
|
||||
congregation: congregationRel
|
||||
};
|
||||
|
||||
try {
|
||||
@ -246,6 +225,19 @@ export default function PublisherForm({ item, me }) {
|
||||
<label className="label" htmlFor="town">Град</label>
|
||||
<input type="text" id="town" name="town" value={publisher.town} onChange={handleChange} className="textbox" placeholder="Град" autoFocus />
|
||||
</div>
|
||||
<div className="mb-4">
|
||||
<label className="label" htmlFor="congregationId">Сбор</label>
|
||||
<select id="congregationId" name="congregationId" value={publisher.congregationId} onChange={handleChange} className="select" placeholder="Община" autoFocus >
|
||||
<option value="">Избери сбор</option>
|
||||
{congregations.map((congregation) => (
|
||||
<option key={congregation.id} value={congregation.id}>
|
||||
{congregation.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
{/* notifications */}
|
||||
<div className="mb-6 p-4 border border-gray-300 rounded-lg">
|
||||
|
Reference in New Issue
Block a user