@@ -28,6 +28,7 @@ import { GetServerSidePropsContext } from "next/types";
28
28
type UserDetailPropsType = {
29
29
user : UserType ;
30
30
books : Array < BookType > ;
31
+ extensionDays : number ;
31
32
} ;
32
33
33
34
const theme = createTheme ( {
@@ -43,7 +44,11 @@ const Alert = forwardRef<HTMLDivElement, AlertProps>(function Alert(
43
44
return < MuiAlert elevation = { 6 } ref = { ref } variant = "filled" { ...props } /> ;
44
45
} ) ;
45
46
46
- export default function UserDetail ( { user, books } : UserDetailPropsType ) {
47
+ export default function UserDetail ( {
48
+ user,
49
+ books,
50
+ extensionDays,
51
+ } : UserDetailPropsType ) {
47
52
const router = useRouter ( ) ;
48
53
49
54
const [ userData , setUserData ] = useState ( user ) ;
@@ -129,12 +134,7 @@ export default function UserDetail({ user, books }: UserDetailPropsType) {
129
134
const newbook = replaceBookStringDate ( book ) as any ;
130
135
//extend logic
131
136
132
- const newDueDate = extendDays (
133
- book . dueDate as Date ,
134
- process . env . EXTENSION_DURATION_DAYS
135
- ? parseInt ( process . env . EXTENSION_DURATION_DAYS )
136
- : 14
137
- ) ;
137
+ const newDueDate = extendDays ( new Date ( ) , extensionDays ) ;
138
138
newbook . dueDate = newDueDate . toDate ( ) ;
139
139
newbook . renewalCount = newbook . renewalCount + 1 ;
140
140
@@ -216,6 +216,7 @@ export default function UserDetail({ user, books }: UserDetailPropsType) {
216
216
}
217
217
218
218
export async function getServerSideProps ( context : GetServerSidePropsContext ) {
219
+ const extensionDays = process . env . EXTENSION_DURATION_DAYS || 14 ;
219
220
if ( ! context . query . userid ) return { props : { } } ;
220
221
const prisma = new PrismaClient ( ) ;
221
222
@@ -248,10 +249,10 @@ export async function getServerSideProps(context: GetServerSidePropsContext) {
248
249
: "" ;
249
250
newBook . dueDate = b . dueDate ? convertDateToDayString ( b . dueDate ) : "" ;
250
251
//temp TODO
251
- console . log ( "Book" , newBook ) ;
252
+ // console.log("Book", newBook);
252
253
return newBook ;
253
254
} ) ;
254
255
255
256
// Pass data to the page via props
256
- return { props : { user, books } } ;
257
+ return { props : { user, books, extensionDays } } ;
257
258
}
0 commit comments