-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
218 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 21 additions & 109 deletions
130
src/components/rpkm/staff/home/qrscanner/QRScanner.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/components/rpkm/staff/home/qrscanner/StudentCodeInput.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import React, { useState } from 'react'; | ||
import toast from 'react-hot-toast'; | ||
|
||
interface StudentCodeInputProps { | ||
sendCheckInRequest: ( | ||
mode: 'userId' | 'studentId', | ||
id: string | ||
) => Promise<void>; | ||
} | ||
|
||
const StudentCodeInput = ({ sendCheckInRequest }: StudentCodeInputProps) => { | ||
const [studentId, setStudentId] = useState<string>(''); | ||
|
||
const handleOnCheckIn = async () => { | ||
if (studentId.length !== 10) { | ||
toast.error('กรุณากรอกรหัสนิสิตให้ครบ 10 หลัก'); | ||
return; | ||
} | ||
|
||
console.log(studentId); | ||
await sendCheckInRequest('studentId', studentId); | ||
}; | ||
|
||
const handleOnChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
const value = e.target.value; | ||
if (!'0123456789'.includes(value.at(-1) || '') || value.length > 10) { | ||
return; | ||
} | ||
setStudentId(value); | ||
}; | ||
|
||
return ( | ||
<div className="flex flex-col items-center justify-center gap-2"> | ||
<div className="text-lg">กรอกรหัสนิสิต</div> | ||
<input | ||
className="w-full px-4 py-1 text-xl border rounded-md border-project-dark-blue focus:outline-none focus:border-blue-500" | ||
type="text" | ||
value={studentId} | ||
onChange={handleOnChange} | ||
placeholder="รหัสนิสิต" | ||
/> | ||
<button | ||
className="text-xl px-4 bg-rpkm-blue text-white rounded-md focus:outline-none" | ||
onClick={handleOnCheckIn} | ||
> | ||
submit | ||
</button> | ||
</div> | ||
); | ||
}; | ||
|
||
export default StudentCodeInput; |
Oops, something went wrong.