From cf90cae4ebc78d3cfed20d5e2f1bf8d29e5868cf Mon Sep 17 00:00:00 2001 From: Joao Ramos Date: Sat, 23 Dec 2023 14:29:24 +0000 Subject: [PATCH] Blocked Corporate user update through payment records screen --- src/components/Low/Checkbox.tsx | 8 +- src/components/UserCard.tsx | 144 ++++++++++++++++++++++++-------- src/pages/payment-record.tsx | 74 +++++++++++----- 3 files changed, 171 insertions(+), 55 deletions(-) diff --git a/src/components/Low/Checkbox.tsx b/src/components/Low/Checkbox.tsx index e5e9656d..d5a7298d 100644 --- a/src/components/Low/Checkbox.tsx +++ b/src/components/Low/Checkbox.tsx @@ -6,11 +6,15 @@ interface Props { isChecked: boolean; onChange: (isChecked: boolean) => void; children: ReactNode; + disabled?: boolean; } -export default function Checkbox({isChecked, onChange, children}: Props) { +export default function Checkbox({isChecked, onChange, children, disabled}: Props) { return ( -
onChange(!isChecked)}> +
{ + if(disabled) return; + onChange(!isChecked); + }}>
void; onViewTeachers?: () => void; onViewCorporate?: () => void; + disabled?: boolean; } -const UserCard = ({user, loggedInUser, onClose, onViewStudents, onViewTeachers, onViewCorporate}: Props) => { +const USER_STATUS_OPTIONS = [ + { + value: 'active', + label: 'Active', + }, { + value: 'disabled', + label: 'Disabled', + }, { + value: 'paymentDue', + label: 'Payment Due', + } +]; + +const USER_TYPE_OPTIONS = Object.keys(USER_TYPE_LABELS).map((type) => ({ + value: type, + label: USER_TYPE_LABELS[type as keyof typeof USER_TYPE_LABELS] +})); + +const CURRENCIES_OPTIONS = CURRENCIES.map(({ label, currency}) => ({ value: currency, label })); + +const UserCard = ({user, loggedInUser, onClose, onViewStudents, onViewTeachers, onViewCorporate, disabled = false}: Props) => { const [expiryDate, setExpiryDate] = useState(user.subscriptionExpirationDate); const [type, setType] = useState(user.type); const [status, setStatus] = useState(user.status); @@ -154,6 +175,7 @@ const UserCard = ({user, loggedInUser, onClose, onViewStudents, onViewTeachers, placeholder="Enter corporate name" defaultValue={companyName} required + disabled={disabled} />
@@ -178,6 +201,7 @@ const UserCard = ({user, loggedInUser, onClose, onViewStudents, onViewTeachers, onChange={setCompanyName} placeholder="Enter corporate name" defaultValue={companyName} + disabled={disabled} /> setUserAmount(e ? parseInt(e) : undefined)} placeholder="Enter number of users" defaultValue={userAmount} + disabled={disabled} /> setMonthlyDuration(e ? parseInt(e) : undefined)} placeholder="Enter monthly duration" defaultValue={monthlyDuration} + disabled={disabled} />
@@ -204,17 +230,31 @@ const UserCard = ({user, loggedInUser, onClose, onViewStudents, onViewTeachers, type="number" defaultValue={paymentValue || 0} className="col-span-3" + disabled={disabled} + /> + setPaymentCurrency(e.target.value)} - className="p-6 col-span-2 w-full min-h-[70px] flex justify-center text-sm font-normal rounded-full border focus:outline-none cursor-pointer bg-white"> - {CURRENCIES.map(({label, currency}) => ( - - ))} -
@@ -249,6 +289,7 @@ const UserCard = ({user, loggedInUser, onClose, onViewStudents, onViewTeachers, color: state.isFocused ? "black" : styles.color, }), }} + isDisabled={disabled} /> )} @@ -262,6 +303,7 @@ const UserCard = ({user, loggedInUser, onClose, onViewStudents, onViewTeachers, type="number" defaultValue={commissionValue || 0} className="col-span-3" + disabled={disabled} /> ) : ( @@ -316,7 +358,8 @@ const UserCard = ({user, loggedInUser, onClose, onViewStudents, onViewTeachers, + className="grid grid-cols-2 items-center gap-4 place-items-center" + disabled={disabled}> {EMPLOYMENT_STATUS.map(({status, label}) => ( {({checked}) => ( @@ -351,7 +394,11 @@ const UserCard = ({user, loggedInUser, onClose, onViewStudents, onViewTeachers,
- + {({checked}) => ( Expiry Date setExpiryDate(checked ? user.subscriptionExpirationDate || new Date() : null)}> + onChange={(checked) => setExpiryDate(checked ? user.subscriptionExpirationDate || new Date() : null)} + disabled={disabled} + > Enabled
@@ -434,6 +483,7 @@ const UserCard = ({user, loggedInUser, onClose, onViewStudents, onViewTeachers, dateFormat="dd/MM/yyyy" selected={moment(expiryDate).toDate()} onChange={(date) => setExpiryDate(date)} + disabled={disabled} /> )}
@@ -445,27 +495,55 @@ const UserCard = ({user, loggedInUser, onClose, onViewStudents, onViewTeachers,
- + setType(e.target.value as typeof user.type)} - className="p-6 w-full min-h-[70px] flex justify-center text-sm font-normal rounded-full border focus:outline-none cursor-pointer bg-white"> - {Object.keys(USER_TYPE_LABELS).map((type) => ( - - ))} - +