Skip to content
This repository has been archived by the owner on Sep 25, 2023. It is now read-only.

Commit

Permalink
feat: added score update and finalized student profile view
Browse files Browse the repository at this point in the history
  • Loading branch information
soulsam480 committed May 26, 2022
1 parent 63ff384 commit 0307f12
Show file tree
Hide file tree
Showing 23 changed files with 233 additions and 182 deletions.
3 changes: 0 additions & 3 deletions .eslintrc-auto-import.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"IconLaCheckCircleSolid": true,
"IconLaChevronDown": true,
"IconLaExclamationCircle": true,
"IconLaExclamationTriangle": true,
"IconLaFileAltSolid": true,
"IconLaFlask": true,
"IconLaGraduationCap": true,
Expand All @@ -27,8 +26,6 @@
"IconLaSchool": true,
"IconLaShieldAlt": true,
"IconLaSitemap": true,
"IconLaSortAmountDown": true,
"IconLaSortAmountUp": true,
"IconLaSun": true,
"IconLaTicketAlt": true,
"IconLaTimes": true,
Expand Down
10 changes: 9 additions & 1 deletion api/src/lib/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,15 @@ export function prismaQueryHelper(client: WithExcludeClient) {
account = await client.account.findFirst({
where: { email, id },
select: {
tenant: true,
tenant: {
include: {
basics: {
select: {
name: true,
},
},
},
},
...client.$exclude('account', ['password', 'otp', 'otpExpiry', 'emailToken']),
},
})
Expand Down
2 changes: 0 additions & 2 deletions api/src/lib/student.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,8 @@ export async function createStudent({
await miraiClient.studentScore.create({
data: {
studentId,
aggregatePercentage: '0',
courseStartedAt: batch.startsAt,
currentTerm: 0,
hasBacklog: false,
lateralEntry: false,
scores: '{}',
},
Expand Down
12 changes: 0 additions & 12 deletions api/src/routes/tickets.ts

This file was deleted.

40 changes: 15 additions & 25 deletions api/src/rpc/routers/student/score.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,9 @@
import { createRouter } from '../../createRouter'
import { z } from 'zod'
import { createStudentScoreSchema } from '@mirai/app'
import { TRPCError } from '@trpc/server'
import { semUpdateSchema } from '@mirai/app'

export const scoreRouter = createRouter()
.mutation('manage', {
input: createStudentScoreSchema,
async resolve({ ctx, input }) {
const { studentId, ...data } = input

const result = await ctx.prisma.studentScore.upsert({
where: { studentId },
create: input,
update: data,
})

return result
},
})
.mutation('remove', {
input: z.number(),
async resolve({ ctx, input }) {
try {
await ctx.prisma.studentScore.delete({ where: { id: input } })
} catch (error) {
throw new TRPCError({ code: 'INTERNAL_SERVER_ERROR', message: 'Unable to delete score' })
}
},
})
.query('get', {
input: z.number(),
async resolve({ ctx, input }) {
Expand All @@ -41,6 +17,20 @@ export const scoreRouter = createRouter()
message: 'Student score details not found !',
})
}

return scoreDetails
},
})
.mutation('update_score_card', {
input: z.object({ studentId: z.number(), data: z.record(semUpdateSchema) }),
async resolve({ ctx, input: { data, studentId } }) {
const scoreData = await ctx.prisma.studentScore.update({
where: { studentId },
data: {
scores: data,
},
})

return scoreData
},
})
3 changes: 0 additions & 3 deletions app/auto-imports.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ declare global {
const IconLaCheckCircleSolid: typeof import('~icons/la/check-circle-solid.jsx')['default']
const IconLaChevronDown: typeof import('~icons/la/chevron-down.jsx')['default']
const IconLaExclamationCircle: typeof import('~icons/la/exclamation-circle.jsx')['default']
const IconLaExclamationTriangle: typeof import('~icons/la/exclamation-triangle.jsx')['default']
const IconLaFileAltSolid: typeof import('~icons/la/file-alt-solid.jsx')['default']
const IconLaFlask: typeof import('~icons/la/flask.jsx')['default']
const IconLaGraduationCap: typeof import('~icons/la/graduation-cap.jsx')['default']
Expand All @@ -28,8 +27,6 @@ declare global {
const IconLaSchool: typeof import('~icons/la/school.jsx')['default']
const IconLaShieldAlt: typeof import('~icons/la/shield-alt.jsx')['default']
const IconLaSitemap: typeof import('~icons/la/sitemap.jsx')['default']
const IconLaSortAmountDown: typeof import('~icons/la/sort-amount-down.jsx')['default']
const IconLaSortAmountUp: typeof import('~icons/la/sort-amount-up.jsx')['default']
const IconLaSun: typeof import('~icons/la/sun.jsx')['default']
const IconLaTicketAlt: typeof import('~icons/la/ticket-alt.jsx')['default']
const IconLaTimes: typeof import('~icons/la/times.jsx')['default']
Expand Down
6 changes: 3 additions & 3 deletions app/src/components/globals/NavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export const NavBar: React.FC<Props> = () => {
<>
<div className="dropdown dropdown-end" onClick={() => setSidebar(false)}>
<button tabIndex={0} className="placeholder avatar">
<div className="h-8 w-8 rounded-full bg-primary text-base-content">
<span> {userData.name?.slice(0, 2).toUpperCase()} </span>
<div className="h-8 w-8 rounded-full bg-base-200 text-sm shadow">
<span> {(userData.name ?? userData?.tenant?.basics?.name)?.slice(0, 2).toUpperCase()} </span>
</div>
</button>
<ul
Expand All @@ -52,7 +52,7 @@ export const NavBar: React.FC<Props> = () => {
<li>
<div className="p-1 text-sm">
<span className="font-semibold text-base-content">
{userData.name} ({userData.role})
{userData.name ?? userData?.tenant?.basics?.name} ({userData.role})
</span>
</div>
</li>
Expand Down
5 changes: 3 additions & 2 deletions app/src/components/lib/MDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface Props {
children: React.ReactChild
noEscape?: boolean
className?: string
afterLeave?: () => void
}

interface ContentProps {
Expand All @@ -28,9 +29,9 @@ const DialogContent = React.forwardRef<HTMLDivElement, ContentProps>(({ children
)
})

export const MDialog: React.FC<Props> = ({ show, children, onClose, noEscape, className }) => {
export const MDialog: React.FC<Props> = ({ show, children, onClose, noEscape, className, afterLeave }) => {
return (
<Transition appear unmount show={show} as={Fragment} static={noEscape}>
<Transition appear unmount show={show} as={Fragment} static={noEscape} afterLeave={afterLeave}>
<Dialog
as="div"
className="fixed inset-0 z-10 flex max-h-screen items-center justify-center overflow-y-hidden"
Expand Down
6 changes: 5 additions & 1 deletion app/src/components/student/ProfileSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ interface Props extends HTMLProps<HTMLDivElement> {}
export const ProfileSection = React.forwardRef<HTMLDivElement, Props>(
({ children, className: _className = '', ...rest }, ref) => {
return (
<div {...rest} className={clsx(['rounded-md p-2 transition-all duration-200 xl:w-[70%]', _className])} ref={ref}>
<div
{...rest}
className={clsx(['max-w-full rounded-md p-2 transition-all duration-200 xl:w-[70%]', _className])}
ref={ref}
>
{children}
</div>
)
Expand Down
60 changes: 30 additions & 30 deletions app/src/components/student/profile/Basics/BasicsCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@ export const BasicsCard: React.FC<Props> = ({ studentBasics, onTrigger }) => {
</button>
</div>

<div className="flex justify-start gap-2 text-sm">
<div className="flex min-w-[150px] flex-none flex-col gap-1">
<div>Name: </div>
<div>Gender: </div>
<div>Category: </div>
<div>Date of birth: </div>
</div>
<div className="grid grid-cols-4 gap-2 text-sm">
<div>Name </div>
<div className="col-span-3">{studentBasics?.name ?? '-'}</div>

<div>Gender </div>
<div className="col-span-3">{studentBasics?.gender ?? '-'}</div>

<div className="flex flex-grow flex-col gap-1">
<div>{studentBasics?.name ?? '-'}</div>
<div>{studentBasics?.gender ?? '-'}</div>
<div>{studentBasics?.category ?? '-'}</div>
<div>{(studentBasics?.dob !== undefined && formatDate(studentBasics.dob, 'DD MMM YYYY')) || '-'}</div>
<div>Category </div>
<div className="col-span-3">{studentBasics?.category ?? '-'}</div>

<div>Date of birth </div>
<div className="col-span-3">
{(studentBasics?.dob !== undefined && formatDate(studentBasics.dob, 'DD MMM YYYY')) || '-'}
</div>
</div>

Expand Down Expand Up @@ -75,26 +75,26 @@ export const BasicsCard: React.FC<Props> = ({ studentBasics, onTrigger }) => {
</button>
</div>

<div className="flex justify-start gap-2 text-sm">
<div className="flex min-w-[150px] flex-none flex-col gap-1">
<div>Mobile Number: </div>
<div>Primary Email: </div>
<div>Secondary Email: </div>
<div>Permanent address: </div>
<div>Current address: </div>
<div className="grid grid-cols-4 gap-2 text-sm">
<div>Mobile Number </div>
<div className="col-span-3">{studentBasics?.mobileNumber ?? '-'}</div>

<div>Primary Email </div>
<div className="col-span-3">{studentBasics?.primaryEmail ?? '-'}</div>

<div>Secondary Email </div>
<div className="col-span-3">{studentBasics?.secondaryEmail ?? '-'}</div>

<div>Permanent address </div>
{/* // TODO: break when length is more */}
<div className="col-span-3 max-w-full break-words">
{studentBasics?.permanentAddress === undefined ? '-' : normalizeAddress(studentBasics.permanentAddress)}
</div>

<div className="flex flex-grow flex-col gap-1">
<div>{studentBasics?.mobileNumber ?? '-'}</div>
<div>{studentBasics?.primaryEmail ?? '-'}</div>
<div>{studentBasics?.secondaryEmail ?? '-'}</div>
{/* // TODO: break when length is more */}
<div className="truncate">
{studentBasics?.permanentAddress === undefined ? '-' : normalizeAddress(studentBasics.permanentAddress)}
</div>
<div className="truncate">
{studentBasics?.currentAddress === undefined ? '-' : normalizeAddress(studentBasics.currentAddress)}
</div>
<div>Current address </div>

<div className="col-span-3 max-w-full break-words">
{studentBasics?.currentAddress === undefined ? '-' : normalizeAddress(studentBasics.currentAddress)}
</div>
</div>
</div>
Expand Down
20 changes: 5 additions & 15 deletions app/src/components/student/profile/Basics/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,10 @@ import { useUser } from 'stores/user'
import { z } from 'zod'
import { BasicsCard } from './BasicsCard'
import { formatDate } from 'utils/helpers'
import { CATEGORY_TYPES, GENDER_TYPES } from 'utils/constnts'

interface Props {}

const GENDER_TYPES = ['MALE', 'FEMALE', 'OTHER'].map((o) => ({ label: o, value: o }))
const CATEGORY_TYPES = [
'General',
'Scheduled Caste',
'Scheduled Tribe',
'Other Backward Classes',
'Economically Weaker Section',
].map((v) => ({ label: v, value: v }))

const ADDRES_FIELDS: Array<keyof StudentAddress> = ['address', 'city', 'district', 'state', 'pin', 'country']

const initialAddress = {
Expand Down Expand Up @@ -62,10 +54,8 @@ export const Basics: React.FC<Props> = () => {
name: '',
category: '',
gender: '',
// TODO: it's here for now as student onboarding setup is not done
// once we have that ready, basics data will be here by default from API
mobileNumber: '8917300318',
primaryEmail: '[email protected]',
mobileNumber: '',
primaryEmail: '',
secondaryEmail: '',
currentAddress: initialAddress,
permanentAddress: initialAddress,
Expand Down Expand Up @@ -159,11 +149,11 @@ export const Basics: React.FC<Props> = () => {

return (
<div className="flex flex-col gap-2">
<div className="text-lg font-medium leading-6 text-gray-900">Basic info</div>
<div className="text-lg font-medium leading-6">Basic info</div>

<BasicsCard studentBasics={studentBasics} onTrigger={handleTriggerDialog} />

<MDialog show={isDialog} onClose={() => null}>
<MDialog show={isDialog} onClose={() => null} noEscape>
<MForm
form={form}
onSubmit={handleSubmit((data) => {
Expand Down
Loading

0 comments on commit 0307f12

Please sign in to comment.