Added a National ID/Passport field to the demographic information of a student

This commit is contained in:
Tiago Ribeiro
2024-01-11 11:05:14 +00:00
parent 174398b4f7
commit 0c9f0b3dbd
4 changed files with 61 additions and 19 deletions

View File

@@ -19,6 +19,7 @@ interface Props {
export default function DemographicInformationInput({user, mutateUser}: Props) { export default function DemographicInformationInput({user, mutateUser}: Props) {
const [country, setCountry] = useState<string>(); const [country, setCountry] = useState<string>();
const [phone, setPhone] = useState<string>(); const [phone, setPhone] = useState<string>();
const [passport_id, setPassportID] = useState<string>();
const [gender, setGender] = useState<Gender>(); const [gender, setGender] = useState<Gender>();
const [employment, setEmployment] = useState<EmploymentStatus>(); const [employment, setEmployment] = useState<EmploymentStatus>();
const [position, setPosition] = useState<string>(); const [position, setPosition] = useState<string>();
@@ -39,6 +40,7 @@ export default function DemographicInformationInput({user, mutateUser}: Props) {
gender, gender,
employment: user.type === "corporate" ? undefined : employment, employment: user.type === "corporate" ? undefined : employment,
position: user.type === "corporate" ? position : undefined, position: user.type === "corporate" ? position : undefined,
passport_id,
}, },
agentInformation: user.type === "agent" ? {companyName, commercialRegistration} : undefined, agentInformation: user.type === "agent" ? {companyName, commercialRegistration} : undefined,
}) })
@@ -72,11 +74,23 @@ export default function DemographicInformationInput({user, mutateUser}: Props) {
/> />
</div> </div>
)} )}
<div className="w-full grid grid-cols-2 gap-6">
<div className="relative flex flex-col gap-3 w-full"> <div className="relative flex flex-col gap-3 w-full">
<label className="font-normal text-base text-mti-gray-dim">Country *</label> <label className="font-normal text-base text-mti-gray-dim">Country *</label>
<CountrySelect value={country} onChange={setCountry} /> <CountrySelect value={country} onChange={setCountry} />
</div> </div>
<Input type="tel" name="phone" label="Phone number" onChange={(e) => setPhone(e)} placeholder="Enter phone number" required /> <Input type="tel" name="phone" label="Phone number" onChange={(e) => setPhone(e)} placeholder="Enter phone number" required />
</div>
{user.type === "student" && (
<Input
type="text"
name="passport_id"
label="Passport/National ID"
onChange={(e) => setPassportID(e)}
placeholder="Enter National ID or Passport number"
required
/>
)}
<div className="relative flex flex-col gap-3 w-full"> <div className="relative flex flex-col gap-3 w-full">
<label className="font-normal text-base text-mti-gray-dim">Gender *</label> <label className="font-normal text-base text-mti-gray-dim">Gender *</label>
<RadioGroup value={gender} onChange={setGender} className="flex flex-row justify-between"> <RadioGroup value={gender} onChange={setGender} className="flex flex-row justify-between">

View File

@@ -41,20 +41,22 @@ interface Props {
const USER_STATUS_OPTIONS = [ const USER_STATUS_OPTIONS = [
{ {
value: 'active', value: "active",
label: 'Active', label: "Active",
}, { },
value: 'disabled', {
label: 'Disabled', value: "disabled",
}, { label: "Disabled",
value: 'paymentDue', },
label: 'Payment Due', {
} value: "paymentDue",
label: "Payment Due",
},
]; ];
const USER_TYPE_OPTIONS = Object.keys(USER_TYPE_LABELS).map((type) => ({ const USER_TYPE_OPTIONS = Object.keys(USER_TYPE_LABELS).map((type) => ({
value: type, value: type,
label: USER_TYPE_LABELS[type as keyof typeof USER_TYPE_LABELS] label: USER_TYPE_LABELS[type as keyof typeof USER_TYPE_LABELS],
})); }));
const CURRENCIES_OPTIONS = CURRENCIES.map(({label, currency}) => ({value: currency, label})); const CURRENCIES_OPTIONS = CURRENCIES.map(({label, currency}) => ({value: currency, label}));
@@ -65,6 +67,7 @@ const UserCard = ({user, loggedInUser, onClose, onViewStudents, onViewTeachers,
const [status, setStatus] = useState(user.status); const [status, setStatus] = useState(user.status);
const [referralAgentLabel, setReferralAgentLabel] = useState<string>(); const [referralAgentLabel, setReferralAgentLabel] = useState<string>();
const [position, setPosition] = useState<string | undefined>(user.type === "corporate" ? user.demographicInformation?.position : undefined); const [position, setPosition] = useState<string | undefined>(user.type === "corporate" ? user.demographicInformation?.position : undefined);
const [passport_id, setPassportID] = useState<string | undefined>(user.type === "student" ? user.demographicInformation?.passport_id : undefined);
const [referralAgent, setReferralAgent] = useState(user.type === "corporate" ? user.corporateInformation?.referralAgent : undefined); const [referralAgent, setReferralAgent] = useState(user.type === "corporate" ? user.corporateInformation?.referralAgent : undefined);
const [companyName, setCompanyName] = useState( const [companyName, setCompanyName] = useState(
@@ -352,6 +355,19 @@ const UserCard = ({user, loggedInUser, onClose, onViewStudents, onViewTeachers,
/> />
</div> </div>
{user.type === "student" && (
<Input
type="text"
name="passport_id"
label="Passport/National ID"
onChange={() => null}
placeholder="Enter National ID or Passport number"
value={user.type === "student" ? user.demographicInformation?.passport_id : undefined}
disabled
required
/>
)}
<div className="flex flex-col md:flex-row gap-8 w-full"> <div className="flex flex-col md:flex-row gap-8 w-full">
{user.type !== "corporate" && ( {user.type !== "corporate" && (
<div className="relative flex flex-col gap-3 w-full"> <div className="relative flex flex-col gap-3 w-full">
@@ -397,8 +413,7 @@ const UserCard = ({user, loggedInUser, onClose, onViewStudents, onViewTeachers,
<RadioGroup <RadioGroup
value={user.demographicInformation?.gender} value={user.demographicInformation?.gender}
className="flex flex-row gap-4 justify-between" className="flex flex-row gap-4 justify-between"
disabled={disabled} disabled={disabled}>
>
<RadioGroup.Option value="male"> <RadioGroup.Option value="male">
{({checked}) => ( {({checked}) => (
<span <span
@@ -449,8 +464,7 @@ const UserCard = ({user, loggedInUser, onClose, onViewStudents, onViewTeachers,
<Checkbox <Checkbox
isChecked={!!expiryDate} isChecked={!!expiryDate}
onChange={(checked) => setExpiryDate(checked ? user.subscriptionExpirationDate || new Date() : null)} onChange={(checked) => setExpiryDate(checked ? user.subscriptionExpirationDate || new Date() : null)}
disabled={disabled} disabled={disabled}>
>
Enabled Enabled
</Checkbox> </Checkbox>
</div> </div>

View File

@@ -77,6 +77,7 @@ export interface DemographicInformation {
phone: string; phone: string;
gender: Gender; gender: Gender;
employment: EmploymentStatus; employment: EmploymentStatus;
passport_id?: string;
} }
export interface DemographicCorporateInformation { export interface DemographicCorporateInformation {

View File

@@ -72,6 +72,7 @@ function UserProfile({user, mutateUser}: Props) {
const [employment, setEmployment] = useState<EmploymentStatus | undefined>( const [employment, setEmployment] = useState<EmploymentStatus | undefined>(
user.type === "corporate" ? undefined : user.demographicInformation?.employment, user.type === "corporate" ? undefined : user.demographicInformation?.employment,
); );
const [passport_id, setPassportID] = useState<string | undefined>(user.type === "student" ? user.demographicInformation?.passport_id : undefined);
const [position, setPosition] = useState<string | undefined>(user.type === "corporate" ? user.demographicInformation?.position : undefined); const [position, setPosition] = useState<string | undefined>(user.type === "corporate" ? user.demographicInformation?.position : undefined);
const [companyName, setCompanyName] = useState<string | undefined>(user.type === "agent" ? user.agentInformation?.companyName : undefined); const [companyName, setCompanyName] = useState<string | undefined>(user.type === "agent" ? user.agentInformation?.companyName : undefined);
const [commercialRegistration, setCommercialRegistration] = useState<string | undefined>( const [commercialRegistration, setCommercialRegistration] = useState<string | undefined>(
@@ -152,6 +153,7 @@ function UserProfile({user, mutateUser}: Props) {
employment: user?.type === "corporate" ? undefined : employment, employment: user?.type === "corporate" ? undefined : employment,
position: user?.type === "corporate" ? position : undefined, position: user?.type === "corporate" ? position : undefined,
gender, gender,
passport_id,
}, },
}); });
if (request.status === 200) { if (request.status === 200) {
@@ -193,6 +195,17 @@ function UserProfile({user, mutateUser}: Props) {
required required
/> />
</div> </div>
{user.type === "student" && (
<Input
type="text"
name="passport_id"
label="Passport/National ID"
onChange={(e) => setPassportID(e)}
placeholder="Enter National ID or Passport number"
value={passport_id}
required
/>
)}
<div className="flex flex-col md:flex-row gap-8 w-full"> <div className="flex flex-col md:flex-row gap-8 w-full">
<Input <Input
label="Current Password" label="Current Password"