Skip to content

Commit

Permalink
Fixes: Loan manager Dashboard v2 (#560)
Browse files Browse the repository at this point in the history
Co-authored-by: Hugo Marques <[email protected]>
  • Loading branch information
hugomarquesdev and Hugo Marques authored Sep 25, 2023
1 parent e73adb5 commit ca42c0c
Show file tree
Hide file tree
Showing 7 changed files with 381 additions and 336 deletions.
37 changes: 24 additions & 13 deletions src/components/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,26 @@ import useFilters from '../hooks/useFilters';
import useTranslations from '../libs/Prismic/hooks/useTranslations';

const TableWrapper = styled(Box)`
> div > div {
/* > div > div {
overflow-y: hidden;
} */
p {
word-break: normal;
white-space: nowrap;
}
th {
width: unset;
padding: 0.75rem 1rem;
}
td {
padding: 1rem 1.25rem;
padding: 1rem 1rem;
p {
text-align: left;
}
}
.dropdown > :nth-child(2) {
Expand All @@ -33,6 +47,14 @@ const TableWrapper = styled(Box)`
}
}
tr:first-child {
.dropdown > :nth-child(2) {
top: 2rem;
bottom: unset;
left: auto;
}
}
tr:last-child {
.tooltip {
bottom: 23px;
Expand Down Expand Up @@ -137,17 +159,6 @@ const Table: React.FC<TableProps & Partial<BaseTableProps>> = (props) => {
setSortKey(newSort);
};

// Add .last class to the last dropdown
useEffect(() => {
const elements = document.querySelectorAll('.dropdown');

if (elements.length > 0) {
const lastElement = elements[elements.length - 1];

lastElement.classList.add('last');
}
}, [data]);

return (
<TableWrapper ref={tableRef} {...forwardProps}>
<BaseTable
Expand Down
94 changes: 65 additions & 29 deletions src/modals/Microcredit/ApproveLoan.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
useWatch
} from 'react-hook-form';
import { handleKnownErrors } from 'src/helpers/handleKnownErrors';
import { useEffect, useState } from 'react';
import { useLoanManager } from '@impact-market/utils';
import { usePrismicData } from '../../libs/Prismic/components/PrismicDataProvider';
import Input from '../../components/Input';
Expand All @@ -28,8 +29,10 @@ const ApproveLoan = () => {
enterLoanMaturity,
approveLoan,
loansApproved,
loanMaturityHint,
enterLoanAmount
enterLoanAmount,
loanAmount,
maximumMaturity,
maturity: maturityMonths
} = extractFromView('messages') as any;

const { handleClose, address, mutate } = useModal();
Expand All @@ -44,16 +47,36 @@ const ApproveLoan = () => {
control
});

const period = useWatch({
const amount = useWatch({
control,
name: 'period'
name: 'amount'
});

const amount = useWatch({
const period = useWatch({
control,
name: 'amount'
name: 'period'
});

const [maturity, setMaturity] = useState(0);

const getMaturity = (loanAmount: number) => {
if (loanAmount <= 100) return 1;
if (loanAmount <= 200) return 2;
if (loanAmount <= 250) return 3;
if (loanAmount <= 300) return 4;
if (loanAmount <= 400) return 5;
if (loanAmount <= 500) return 6;
if (loanAmount >= 500) return 9;

return 0;
};

useEffect(() => {
const maturityValue = getMaturity(parseInt(amount, 10));

setMaturity(maturityValue);
}, [amount]);

const { addLoans, managerDetails } = useLoanManager();

const handleCancel = (event: any) => {
Expand Down Expand Up @@ -143,12 +166,33 @@ const ApproveLoan = () => {
large
mt={1}
semibold
mb={1}
/>
<Box mb="1rem">
<Input
type="number"
placeholder={enterLoanAmount}
wrapperProps={{
w: '100%'
}}
suffix="cUSD"
rules={{
required: true
}}
control={control}
name="amount"
withError={!!errors?.amount}
hint={`Max. ${
managerDetails?.currentLentAmountLimit -
managerDetails?.currentLentAmount
} cUSD`}
label={loanAmount}
/>
</Box>
<Input
type="number"
placeholder={enterLoanMaturity[0].text}
wrapperProps={{
mt: 1,
w: '100%'
}}
rules={{
Expand All @@ -157,26 +201,17 @@ const ApproveLoan = () => {
control={control}
name="period"
withError={!!errors?.period}
hint={loanMaturityHint}
/>
<Input
type="number"
placeholder={enterLoanAmount}
wrapperProps={{
mt: 1,
w: '100%'
}}
suffix="cUSD"
rules={{
required: true
}}
control={control}
name="amount"
withError={!!errors?.amount}
hint={`Max. ${
managerDetails?.currentLentAmountLimit -
managerDetails?.currentLentAmount
} cUSD`}
// @ts-ignore
hint={
!!maturity && (
<RichText
small
content={maximumMaturity}
variables={{ maturity }}
/>
)
}
label={maturityMonths}
/>
</Box>

Expand All @@ -196,7 +231,7 @@ const ApproveLoan = () => {
mt={{ sm: 1.5, xs: 1.5 }}
onClick={handleCancel}
>
{t('cancel')}
{t('dismiss')}
</Button>
<Button
fluid={'xs'}
Expand All @@ -207,7 +242,8 @@ const ApproveLoan = () => {
!period ||
!amount ||
validateAmount ||
validatePeriod
validatePeriod ||
parseFloat(period) > maturity
}
isLoading={isSubmitting}
>
Expand Down
Loading

1 comment on commit ca42c0c

@vercel
Copy link

@vercel vercel bot commented on ca42c0c Sep 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

app – ./

app-git-production-ipct.vercel.app
app-ipct.vercel.app
app.impactmarket.com

Please sign in to comment.