From c0bb8683ef398b94984bec4970e5837dd7a51ac4 Mon Sep 17 00:00:00 2001 From: Bittu kumar Date: Thu, 13 Feb 2025 04:29:54 +0530 Subject: [PATCH 01/16] feat(pg-migration): funds and fundraising campaigns --- src/GraphQl/Mutations/CampaignMutation.ts | 66 ++++----- src/GraphQl/Mutations/FundMutation.ts | 45 ++---- src/GraphQl/Queries/fundQueries.ts | 134 +++++++++--------- .../FundCampaignPledge/FundCampaignPledge.tsx | 15 +- .../CampaignModal.tsx | 62 +++++--- .../OrganizationFundCampagins.tsx | 88 +++++------- src/screens/OrganizationFunds/FundModal.tsx | 23 ++- .../OrganizationFunds/OrganizationFunds.tsx | 25 ++-- src/style/app.module.css | 2 +- 9 files changed, 212 insertions(+), 248 deletions(-) diff --git a/src/GraphQl/Mutations/CampaignMutation.ts b/src/GraphQl/Mutations/CampaignMutation.ts index d14d318af6..78e54a0c3a 100644 --- a/src/GraphQl/Mutations/CampaignMutation.ts +++ b/src/GraphQl/Mutations/CampaignMutation.ts @@ -5,35 +5,33 @@ import gql from 'graphql-tag'; * * @param name - The name of the fund. * @param fundId - The fund ID the campaign is associated with. - * @param fundingGoal - The funding goal of the campaign. - * @param startDate - The start date of the campaign. - * @param endDate - The end date of the campaign. - * @param currency - The currency of the campaign. + * @param goalAmount - The funding goal of the campaign. + * @param startAt - The start date of the campaign. + * @param endAt - The end date of the campaign. + * @param currencyCode - The currency of the campaign. * @returns The ID of the created campaign. */ export const CREATE_CAMPAIGN_MUTATION = gql` - mutation createFundraisingCampaign( - $fundId: ID! - $organizationId: ID! + mutation createFundCampaign( $name: String! - $fundingGoal: Float! - $startDate: Date! - $endDate: Date! - $currency: Currency! + $fundId: ID! + $goalAmount: Int! + $startAt: DateTime! + $endAt: DateTime! + $currencyCode: Iso4217CurrencyCode! ) { - createFundraisingCampaign( - data: { + createFundCampaign( + input: { fundId: $fundId - organizationId: $organizationId name: $name - fundingGoal: $fundingGoal - startDate: $startDate - endDate: $endDate - currency: $currency + goalAmount: $goalAmount + startAt: $startAt + endAt: $endAt + currencyCode: $currencyCode } ) { - _id + id } } `; @@ -43,33 +41,17 @@ export const CREATE_CAMPAIGN_MUTATION = gql` * * @param id - The ID of the campaign being updated. * @param name - The name of the campaign. - * @param fundingGoal - The funding goal of the campaign. - * @param startDate - The start date of the campaign. - * @param endDate - The end date of the campaign. - * @param currency - The currency of the campaign. + * @param goalAmount - The funding goal of the campaign. + * @param startAt - The start date of the campaign. + * @param endAt - The end date of the campaign. + * @param currencyCode - The currency of the campaign. * @returns The ID of the updated campaign. */ export const UPDATE_CAMPAIGN_MUTATION = gql` - mutation updateFundraisingCampaign( - $id: ID! - $name: String - $fundingGoal: Float - $startDate: Date - $endDate: Date - $currency: Currency - ) { - updateFundraisingCampaign( - id: $id - data: { - name: $name - fundingGoal: $fundingGoal - startDate: $startDate - endDate: $endDate - currency: $currency - } - ) { - _id + mutation updateFundCampaign($input: MutationUpdateFundCampaignInput!) { + updateFundCampaign(input: $input) { + id } } `; diff --git a/src/GraphQl/Mutations/FundMutation.ts b/src/GraphQl/Mutations/FundMutation.ts index dd7bac8e5f..2d53481272 100644 --- a/src/GraphQl/Mutations/FundMutation.ts +++ b/src/GraphQl/Mutations/FundMutation.ts @@ -5,67 +5,40 @@ import gql from 'graphql-tag'; * * @param name - The name of the fund. * @param organizationId - The organization ID the fund is associated with. - * @param refrenceNumber - The reference number of the fund. - * @param taxDeductible - Whether the fund is tax deductible. - * @param isArchived - Whether the fund is archived. - * @param isDefault - Whether the fund is the default. + * @param isTaxDeductible - Whether the fund is tax deductible. * @returns The ID of the created fund. */ export const CREATE_FUND_MUTATION = gql` mutation CreateFund( $name: String! $organizationId: ID! - $refrenceNumber: String - $taxDeductible: Boolean! - $isArchived: Boolean! - $isDefault: Boolean! + $isTaxDeductible: Boolean! ) { createFund( - data: { + input: { # ✅ Ensure correct field names name: $name organizationId: $organizationId - refrenceNumber: $refrenceNumber - taxDeductible: $taxDeductible - isArchived: $isArchived - isDefault: $isDefault + isTaxDeductible: $isTaxDeductible } ) { - _id + id } } `; + /** * GraphQL mutation to update a fund. * * @param id - The ID of the fund being updated. * @param name - The name of the fund. - * @param refrenceNumber - The reference number of the fund. * @param taxDeductible - Whether the fund is tax deductible. - * @param isArchived - Whether the fund is archived. - * @param isDefault - Whether the fund is the default. * @returns The ID of the updated fund. */ export const UPDATE_FUND_MUTATION = gql` - mutation UpdateFund( - $id: ID! - $name: String - $refrenceNumber: String - $taxDeductible: Boolean - $isArchived: Boolean - $isDefault: Boolean - ) { - updateFund( - id: $id - data: { - name: $name - refrenceNumber: $refrenceNumber - taxDeductible: $taxDeductible - isArchived: $isArchived - isDefault: $isDefault - } - ) { - _id + mutation UpdateFund($input: MutationUpdateFundInput!) { + updateFund(input: $input) { + id } } `; diff --git a/src/GraphQl/Queries/fundQueries.ts b/src/GraphQl/Queries/fundQueries.ts index f705b87797..ff56debc1b 100644 --- a/src/GraphQl/Queries/fundQueries.ts +++ b/src/GraphQl/Queries/fundQueries.ts @@ -1,87 +1,89 @@ -/*eslint-disable*/ +/* eslint-disable */ import gql from 'graphql-tag'; /** * GraphQL query to retrieve the list of members for a specific organization. * * @param id - The ID of the organization for which members are being retrieved. - * @param filter - The filter to search for a specific member. + * @params name - The name of the organization for which members are being retrieved. + * @params creatorId - The ID of the creator of the organization. + * @params updaterId - The ID of the user who last updated the organization. + * @params isTaxDeductible - A boolean value indicating whether the organization is tax deductible. * @returns The list of members associated with the organization. */ export const FUND_LIST = gql` - query FundsByOrganization( - $organizationId: ID! - $filter: String - $orderBy: FundOrderByInput - ) { - fundsByOrganization( - organizationId: $organizationId - where: { name_contains: $filter } - orderBy: $orderBy - ) { - _id - name - refrenceNumber - taxDeductible - isDefault - isArchived - createdAt - organizationId - creator { - _id - firstName - lastName +query FundsByOrganization($input: QueryOrganizationInput!) { + organization(input: $input) { + funds(first: 32) { + edges { + node { + creator { + id + } + id + isTaxDeductible + name + organization { + id + } + updater { + id + } + } } } } +} `; +/** + * Query to fetch a specific fund by its ID, along with its associated campaigns. + * @params id - The ID of the fund campaign to be fetched. + * @params name - The name of the fund campaign to be fetched. + * @params sratAt - The start date of the fund campaign to be fetched. + * @params endAt - The end date of the fund campaign to be fetched. + * @params currencyCode - The currency code of the fund campaign to be fetched. + * @params goalAmount - The goal amount of the fund campaign to be fetched. + * @returns The fund campaign with the specified ID. + */ + export const FUND_CAMPAIGN = gql` - query GetFundById( - $id: ID! - $where: CampaignWhereInput - $orderBy: CampaignOrderByInput - ) { - getFundById(id: $id, where: $where, orderBy: $orderBy) { + query GetFundById($input: QueryFundInput!) { + fund(input: $input) { + id name - isArchived - campaigns { - _id - endDate - fundingGoal - name - startDate - currency + campaigns(first: 10) { + edges { + node { + id + name + startAt + endAt + currencyCode + goalAmount + } + } } } } `; export const FUND_CAMPAIGN_PLEDGE = gql` - query GetFundraisingCampaigns( - $where: CampaignWhereInput - $pledgeOrderBy: PledgeOrderByInput - ) { - getFundraisingCampaigns(where: $where, pledgeOrderBy: $pledgeOrderBy) { - fundId { - name - } + query GetFundCampaignPledges($input: QueryFundCampaignInput!) { + fundCampaign(input: $input) { + id name - fundingGoal - currency - startDate - endDate - pledges { - _id - amount - currency - endDate - startDate - users { - _id - firstName - lastName - image + pledges(first: 10) { + edges { + node { + id + amount + note + pledger { + id + name + } + } } } } @@ -93,13 +95,13 @@ export const USER_FUND_CAMPAIGNS = gql` $where: CampaignWhereInput $campaignOrderBy: CampaignOrderByInput ) { - getFundraisingCampaigns(where: $where, campaignOrderby: $campaignOrderBy) { - _id - startDate - endDate + getFundraisingCampaigns(where: $where, campaignOrderBy: $campaignOrderBy) { + id name - fundingGoal currency + fundingGoal + startDate + endDate } } `; diff --git a/src/screens/FundCampaignPledge/FundCampaignPledge.tsx b/src/screens/FundCampaignPledge/FundCampaignPledge.tsx index 712447b170..e0a540482e 100644 --- a/src/screens/FundCampaignPledge/FundCampaignPledge.tsx +++ b/src/screens/FundCampaignPledge/FundCampaignPledge.tsx @@ -142,14 +142,15 @@ const fundCampaignPledge = (): JSX.Element => { getFundraisingCampaigns: InterfaceQueryFundCampaignsPledges[]; }> >; - } = useQuery(FUND_CAMPAIGN_PLEDGE, { - variables: { - where: { - id: fundCampaignId, + } + = useQuery(FUND_CAMPAIGN_PLEDGE, { + variables: { + input: { + id: fundCampaignId, + }, + pledgeOrderBy: sortBy, }, - pledgeOrderBy: sortBy, - }, - }); + }); const endDate = dayjs( pledgeData?.getFundraisingCampaigns[0]?.endDate, diff --git a/src/screens/OrganizationFundCampaign/CampaignModal.tsx b/src/screens/OrganizationFundCampaign/CampaignModal.tsx index ec0b81f436..291d90a415 100644 --- a/src/screens/OrganizationFundCampaign/CampaignModal.tsx +++ b/src/screens/OrganizationFundCampaign/CampaignModal.tsx @@ -107,19 +107,29 @@ const CampaignModal: React.FC = ({ * @param e - The form event. * @returns Promise */ - const createCampaignHandler = async ( - e: ChangeEvent, - ): Promise => { + const createCampaignHandler = async (e: ChangeEvent) => { e.preventDefault(); + + // Ensure the end date is in the future + if (dayjs(formState.campaignEndDate).isBefore(dayjs())) { + toast.error("End date must be in the future."); + return; + } + + // Ensure the end date is different from the start date + if (dayjs(formState.campaignEndDate).isSame(dayjs(formState.campaignStartDate))) { + toast.error("End date must be different from the start date."); + return; + } + try { await createCampaign({ variables: { name: formState.campaignName, - currency: formState.campaignCurrency, - fundingGoal: formState.campaignGoal, - organizationId: orgId, - startDate: dayjs(formState.campaignStartDate).format('YYYY-MM-DD'), - endDate: dayjs(formState.campaignEndDate).format('YYYY-MM-DD'), + currencyCode: formState.campaignCurrency, + goalAmount: parseInt(formState.campaignGoal, 10), + startAt: dayjs(formState.campaignStartDate).toISOString(), + endAt: dayjs(formState.campaignEndDate).toISOString(), fundId, }, }); @@ -129,7 +139,7 @@ const CampaignModal: React.FC = ({ campaignCurrency: 'USD', campaignGoal: 0, campaignStartDate: new Date(), - campaignEndDate: new Date(), + campaignEndDate: dayjs().add(1, 'day').toDate(), }); refetchCampaign(); hide(); @@ -149,29 +159,43 @@ const CampaignModal: React.FC = ({ e: ChangeEvent, ): Promise => { e.preventDefault(); + + // Ensure the end date is in the future + if (dayjs(formState.campaignEndDate).isBefore(dayjs())) { + toast.error("End date must be in the future."); + return; + } + + // Ensure the end date is different from the start date + if (dayjs(formState.campaignEndDate).isSame(dayjs(formState.campaignStartDate))) { + toast.error("End date must be different from the start date."); + return; + } try { const updatedFields: { [key: string]: string | number | undefined } = {}; if (campaign?.name !== campaignName) { updatedFields.name = campaignName; } - if (campaign?.currency !== campaignCurrency) { - updatedFields.currency = campaignCurrency; - } if (campaign?.fundingGoal !== campaignGoal) { - updatedFields.fundingGoal = campaignGoal; + updatedFields.goalAmount = campaignGoal; } if (campaign?.startDate !== campaignStartDate) { - updatedFields.startDate = dayjs(campaignStartDate).format('YYYY-MM-DD'); + updatedFields.startAt = dayjs(campaignStartDate).toISOString(); } if (campaign?.endDate !== formState.campaignEndDate) { - updatedFields.endDate = dayjs(formState.campaignEndDate).format( - 'YYYY-MM-DD', - ); + const endAt = dayjs(formState.campaignEndDate); + if (endAt.isBefore(dayjs())) { + toast.error("End date must be in the future."); + return; + } + updatedFields.endAt = endAt.toISOString(); } await updateCampaign({ variables: { - id: campaign?._id, - ...updatedFields, + input: { + id: campaign?.id, // Ensure the id field is the campaign id + ...updatedFields, + }, }, }); setFormState({ diff --git a/src/screens/OrganizationFundCampaign/OrganizationFundCampagins.tsx b/src/screens/OrganizationFundCampaign/OrganizationFundCampagins.tsx index 5858c1dbc8..87a3ce2aa4 100644 --- a/src/screens/OrganizationFundCampaign/OrganizationFundCampagins.tsx +++ b/src/screens/OrganizationFundCampaign/OrganizationFundCampagins.tsx @@ -147,14 +147,19 @@ const orgFundCampaign = (): JSX.Element => { refetch: () => void; } = useQuery(FUND_CAMPAIGN, { variables: { - id: fundId, - orderBy: sortBy, - where: { - name_contains: searchTerm, - }, + input: { id: fundId }, // Updated to use 'input' }, + skip: !fundId, + onCompleted: (data) => console.log("GraphQL Data Received:", data), + onError: (error) => console.error("GraphQL Error:", error), }); + const compaignsData = useMemo(() => { + return campaignData?.fund?.campaigns?.edges.map(edge => edge.node) ?? []; + }, [campaignData]); + + console.log("compaignsData", compaignsData); + const handleClick = (campaignId: string): void => { navigate(`/fundCampaignPledge/${orgId}/${campaignId}`); }; @@ -206,17 +211,15 @@ const orgFundCampaign = (): JSX.Element => { headerAlign: 'center', headerClassName: `${styles.tableHeader}`, sortable: false, - renderCell: (params: GridCellParams) => { - return ( -
handleClick(params.row.campaign._id as string)} - > - {params.row.campaign.name} -
- ); - }, + renderCell: (params: GridCellParams) => ( +
handleClick(params.row.id as string)} + > + {params.row.name} +
+ ), }, { field: 'startDate', @@ -226,9 +229,8 @@ const orgFundCampaign = (): JSX.Element => { headerAlign: 'center', headerClassName: `${styles.tableHeader}`, sortable: false, - renderCell: (params: GridCellParams) => { - return dayjs(params.row.campaign.startDate).format('DD/MM/YYYY'); - }, + renderCell: (params: GridCellParams) => + dayjs(params.row.startAt).format('DD/MM/YYYY'), }, { field: 'endDate', @@ -241,7 +243,7 @@ const orgFundCampaign = (): JSX.Element => { renderCell: (params: GridCellParams) => { return (
- {dayjs(params.row.campaign.endDate).format('DD/MM/YYYY')}{' '} + {dayjs(params.row.endAt).format('DD/MM/YYYY')}{' '}
); }, @@ -263,10 +265,10 @@ const orgFundCampaign = (): JSX.Element => { > { currencySymbols[ - params.row.campaign.currency as keyof typeof currencySymbols + params.row.currencyCode as keyof typeof currencySymbols ] } - {params.row.campaign.fundingGoal} + {params.row.goalAmount} ); }, @@ -288,7 +290,7 @@ const orgFundCampaign = (): JSX.Element => { > { currencySymbols[ - params.row.campaign.currency as keyof typeof currencySymbols + params.row.currencyCode as keyof typeof currencySymbols ] } 0 @@ -305,26 +307,17 @@ const orgFundCampaign = (): JSX.Element => { headerAlign: 'center', headerClassName: `${styles.tableHeader}`, sortable: false, - renderCell: (params: GridCellParams) => { - return ( - <> - - - ); - }, + renderCell: (params: GridCellParams) => ( + + ), }, { field: 'assocPledge', @@ -342,7 +335,7 @@ const orgFundCampaign = (): JSX.Element => { size="sm" className={styles.editButton} data-testid="viewBtn" - onClick={() => handleClick(params.row.campaign._id as string)} + onClick={() => handleClick(params.row.id as string)} > {t('viewPledges')} @@ -415,7 +408,7 @@ const orgFundCampaign = (): JSX.Element => { disableColumnMenu columnBufferPx={8} hideFooter={true} - getRowId={(row) => row.campaign._id} + getRowId={(row) => row.id} slots={{ noRowsOverlay: () => ( @@ -429,10 +422,7 @@ const orgFundCampaign = (): JSX.Element => { } autoHeight rowHeight={65} - rows={campaigns.map((campaign, index) => ({ - id: index + 1, - campaign, - }))} + rows={compaignsData} columns={columns} isRowSelectable={() => false} /> diff --git a/src/screens/OrganizationFunds/FundModal.tsx b/src/screens/OrganizationFunds/FundModal.tsx index e5c44cd2e0..47f817b90c 100644 --- a/src/screens/OrganizationFunds/FundModal.tsx +++ b/src/screens/OrganizationFunds/FundModal.tsx @@ -109,9 +109,8 @@ const FundModal: React.FC = ({ await createFund({ variables: { name: fundName, - refrenceNumber: fundRef, organizationId: orgId, - taxDeductible, + isTaxDeductible: taxDeductible, isArchived, isDefault, }, @@ -136,32 +135,25 @@ const FundModal: React.FC = ({ e: ChangeEvent, ): Promise => { e.preventDefault(); - const { fundName, fundRef, taxDeductible, isArchived, isDefault } = + const { fundName, taxDeductible } = formState; try { const updatedFields: { [key: string]: string | boolean } = {}; if (fundName != fund?.name) { updatedFields.name = fundName; } - if (fundRef != fund?.refrenceNumber) { - updatedFields.refrenceNumber = fundRef; - } if (taxDeductible != fund?.taxDeductible) { - updatedFields.taxDeductible = taxDeductible; - } - if (isArchived != fund?.isArchived) { - updatedFields.isArchived = isArchived; - } - if (isDefault != fund?.isDefault) { - updatedFields.isDefault = isDefault; + updatedFields.isTaxDeductible = taxDeductible; } if (Object.keys(updatedFields).length === 0) { return; } await updateFund({ variables: { - id: fund?._id, - ...updatedFields, + input: { + id: fund?.id, + ...updatedFields, + }, }, }); setFormState({ @@ -299,4 +291,5 @@ const FundModal: React.FC = ({ ); }; + export default FundModal; diff --git a/src/screens/OrganizationFunds/OrganizationFunds.tsx b/src/screens/OrganizationFunds/OrganizationFunds.tsx index c0b2a2b7f7..e24280410e 100644 --- a/src/screens/OrganizationFunds/OrganizationFunds.tsx +++ b/src/screens/OrganizationFunds/OrganizationFunds.tsx @@ -149,13 +149,15 @@ const organizationFunds = (): JSX.Element => { refetch: () => void; } = useQuery(FUND_LIST, { variables: { - organizationId: orgId, - filter: searchTerm, - orderBy: sortBy, - }, + input: { + id: orgId, + } + } }); - const funds = useMemo(() => fundData?.fundsByOrganization ?? [], [fundData]); + const funds = useMemo(() => { + return fundData?.organization?.funds?.edges.map(edge => edge.node) ?? []; + }, [fundData]); const handleClick = (fundId: string): void => { navigate(`/orgfundcampaign/${orgId}/${fundId}`); @@ -207,7 +209,7 @@ const organizationFunds = (): JSX.Element => {
handleClick(params.row._id as string)} + onClick={() => handleClick(params.row.id as string)} > {params.row.name}
@@ -224,7 +226,7 @@ const organizationFunds = (): JSX.Element => { sortable: false, headerClassName: `${styles.tableHeader}`, renderCell: (params: GridCellParams) => { - return params.row.creator.firstName + ' ' + params.row.creator.lastName; + return params.row.creator.id; }, }, { @@ -299,7 +301,7 @@ const organizationFunds = (): JSX.Element => { diff --git a/src/screens/OrganizationFunds/FundModal.tsx b/src/screens/OrganizationFunds/FundModal.tsx index 47f817b90c..1985e912fe 100644 --- a/src/screens/OrganizationFunds/FundModal.tsx +++ b/src/screens/OrganizationFunds/FundModal.tsx @@ -135,8 +135,7 @@ const FundModal: React.FC = ({ e: ChangeEvent, ): Promise => { e.preventDefault(); - const { fundName, taxDeductible } = - formState; + const { fundName, taxDeductible } = formState; try { const updatedFields: { [key: string]: string | boolean } = {}; if (fundName != fund?.name) { diff --git a/src/screens/OrganizationFunds/OrganizationFunds.tsx b/src/screens/OrganizationFunds/OrganizationFunds.tsx index e24280410e..7f486c9c88 100644 --- a/src/screens/OrganizationFunds/OrganizationFunds.tsx +++ b/src/screens/OrganizationFunds/OrganizationFunds.tsx @@ -151,12 +151,12 @@ const organizationFunds = (): JSX.Element => { variables: { input: { id: orgId, - } - } + }, + }, }); const funds = useMemo(() => { - return fundData?.organization?.funds?.edges.map(edge => edge.node) ?? []; + return fundData?.organization?.funds?.edges.map((edge) => edge.node) ?? []; }, [fundData]); const handleClick = (fundId: string): void => { From 9397b5d3c98fa00e42b061d4f88edf964e4e9613 Mon Sep 17 00:00:00 2001 From: Bittu kumar Date: Thu, 13 Feb 2025 04:47:56 +0530 Subject: [PATCH 03/16] Fix error --- src/GraphQl/Queries/fundQueries.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/GraphQl/Queries/fundQueries.ts b/src/GraphQl/Queries/fundQueries.ts index a3067eff91..43530d02a8 100644 --- a/src/GraphQl/Queries/fundQueries.ts +++ b/src/GraphQl/Queries/fundQueries.ts @@ -1,4 +1,3 @@ -/* eslint-disable */ import gql from 'graphql-tag'; /** From fcf1b7ca732bdab0001d1c6ce8dd20fc179207d3 Mon Sep 17 00:00:00 2001 From: Bittu kumar Date: Thu, 13 Feb 2025 22:17:32 +0530 Subject: [PATCH 04/16] Fix typecheck error --- src/GraphQl/Mutations/CampaignMutation.ts | 2 +- src/GraphQl/Mutations/FundMutation.ts | 1 - .../CampaignModal.tsx | 38 ++++++++++++------- .../OrganizationFundCampagins.tsx | 6 +-- src/utils/interfaces.ts | 33 +++++++++------- 5 files changed, 48 insertions(+), 32 deletions(-) diff --git a/src/GraphQl/Mutations/CampaignMutation.ts b/src/GraphQl/Mutations/CampaignMutation.ts index 78e54a0c3a..ab1945e44d 100644 --- a/src/GraphQl/Mutations/CampaignMutation.ts +++ b/src/GraphQl/Mutations/CampaignMutation.ts @@ -44,7 +44,7 @@ export const CREATE_CAMPAIGN_MUTATION = gql` * @param goalAmount - The funding goal of the campaign. * @param startAt - The start date of the campaign. * @param endAt - The end date of the campaign. - * @param currencyCode - The currency of the campaign. +// * @param currencyCode - The currency of the campaign. * @returns The ID of the updated campaign. */ diff --git a/src/GraphQl/Mutations/FundMutation.ts b/src/GraphQl/Mutations/FundMutation.ts index 1485881354..0031adc42a 100644 --- a/src/GraphQl/Mutations/FundMutation.ts +++ b/src/GraphQl/Mutations/FundMutation.ts @@ -16,7 +16,6 @@ export const CREATE_FUND_MUTATION = gql` ) { createFund( input: { - # ✅ Ensure correct field names name: $name organizationId: $organizationId isTaxDeductible: $isTaxDeductible diff --git a/src/screens/OrganizationFundCampaign/CampaignModal.tsx b/src/screens/OrganizationFundCampaign/CampaignModal.tsx index 8b3e22c8d1..e159022921 100644 --- a/src/screens/OrganizationFundCampaign/CampaignModal.tsx +++ b/src/screens/OrganizationFundCampaign/CampaignModal.tsx @@ -74,19 +74,19 @@ const CampaignModal: React.FC = ({ const [formState, setFormState] = useState({ campaignName: campaign?.name ?? '', - campaignCurrency: campaign?.currency ?? 'USD', - campaignGoal: campaign?.fundingGoal ?? 0, - campaignStartDate: campaign?.startDate ?? new Date(), - campaignEndDate: campaign?.endDate ?? new Date(), + campaignCurrency: campaign?.currencyCode ?? 'USD', + campaignGoal: campaign?.goalAmount ?? 0, + campaignStartDate: campaign?.startAt ?? new Date(), + campaignEndDate: campaign?.endAt ?? new Date(), }); useEffect(() => { setFormState({ - campaignCurrency: campaign?.currency ?? 'USD', - campaignEndDate: campaign?.endDate ?? new Date(), - campaignGoal: campaign?.fundingGoal ?? 0, + campaignCurrency: campaign?.currencyCode ?? 'USD', + campaignEndDate: campaign?.endAt ?? new Date(), + campaignGoal: campaign?.goalAmount ?? 0, campaignName: campaign?.name ?? '', - campaignStartDate: campaign?.startDate ?? new Date(), + campaignStartDate: campaign?.startAt ?? new Date(), }); }, [campaign]); @@ -131,7 +131,7 @@ const CampaignModal: React.FC = ({ variables: { name: formState.campaignName, currencyCode: formState.campaignCurrency, - goalAmount: parseInt(formState.campaignGoal, 10), + goalAmount: formState.campaignGoal, startAt: dayjs(formState.campaignStartDate).toISOString(), endAt: dayjs(formState.campaignEndDate).toISOString(), fundId, @@ -184,13 +184,13 @@ const CampaignModal: React.FC = ({ if (campaign?.name !== campaignName) { updatedFields.name = campaignName; } - if (campaign?.fundingGoal !== campaignGoal) { + if (campaign?.goalAmount !== campaignGoal) { updatedFields.goalAmount = campaignGoal; } - if (campaign?.startDate !== campaignStartDate) { + if (campaign?.startAt !== campaignStartDate) { updatedFields.startAt = dayjs(campaignStartDate).toISOString(); } - if (campaign?.endDate !== formState.campaignEndDate) { + if (campaign?.endAt !== formState.campaignEndDate) { const endAt = dayjs(formState.campaignEndDate); if (endAt.isBefore(dayjs())) { toast.error('End date must be in the future.'); @@ -198,10 +198,22 @@ const CampaignModal: React.FC = ({ } updatedFields.endAt = endAt.toISOString(); } + + // In mutation, the currencyCode is not updated + // if (campaign?.currencyCode !== campaignCurrency) { + // updatedFields.currencyCode = campaignCurrency; + // } + + // Check if there are any updated fields + if (Object.keys(updatedFields).length === 0) { + toast.error('No changes detected.'); + return; + } + await updateCampaign({ variables: { input: { - id: campaign?.id, // Ensure the id field is the campaign id + id: campaign?.id, ...updatedFields, }, }, diff --git a/src/screens/OrganizationFundCampaign/OrganizationFundCampagins.tsx b/src/screens/OrganizationFundCampaign/OrganizationFundCampagins.tsx index edec1ea68e..5e94deb2f9 100644 --- a/src/screens/OrganizationFundCampaign/OrganizationFundCampagins.tsx +++ b/src/screens/OrganizationFundCampaign/OrganizationFundCampagins.tsx @@ -165,9 +165,9 @@ const orgFundCampaign = (): JSX.Element => { }; const { campaigns, fundName, isArchived } = useMemo(() => { - const fundName = campaignData?.getFundById?.name || 'Fund'; - const isArchived = campaignData?.getFundById?.isArchived || false; - const campaigns = campaignData?.getFundById?.campaigns || []; + const fundName = campaignData?.fund?.name || 'Fund'; + const isArchived = campaignData?.fund?.isArchived || false; + const campaigns = campaignData?.fund?.campaigns || []; return { fundName, campaigns, isArchived }; }, [campaignData]); diff --git a/src/utils/interfaces.ts b/src/utils/interfaces.ts index 38a37f3e27..ddb676a495 100644 --- a/src/utils/interfaces.ts +++ b/src/utils/interfaces.ts @@ -993,18 +993,23 @@ export interface InterfaceQueryOrganizationAdvertisementListItem { } export interface InterfaceQueryOrganizationFundCampaigns { + id: string; name: string; isArchived: boolean; campaigns: { - _id: string; - name: string; - fundingGoal: number; - startDate: Date; - endDate: Date; - createdAt: string; - currency: string; - }[]; + edges: { + node: { + id: string; + name: string; + startAt: string; + endAt: string; + currencyCode: string; + goalAmount: number; + }; + }[]; + }; } + export interface InterfaceUserCampaign { _id: string; name: string; @@ -1025,7 +1030,7 @@ export interface InterfaceQueryFundCampaignsPledges { pledges: InterfacePledgeInfo[]; } export interface InterfaceFundInfo { - _id: string; + id: string; name: string; refrenceNumber: string; taxDeductible: boolean; @@ -1036,13 +1041,13 @@ export interface InterfaceFundInfo { creator: { _id: string; firstName: string; lastName: string }; } export interface InterfaceCampaignInfo { - _id: string; + id: string; name: string; - fundingGoal: number; - startDate: Date; - endDate: Date; + goalAmount: number; + startAt: Date; + endAt: Date; createdAt: string; - currency: string; + currencyCode: string; } export interface InterfacePledgeInfo { _id: string; From f8acf36728935e7d4e4a4b8dce14efbc1c0a5afe Mon Sep 17 00:00:00 2001 From: Bittu kumar Date: Thu, 13 Feb 2025 22:18:20 +0530 Subject: [PATCH 05/16] Fix typecheck error --- src/GraphQl/Queries/fundQueries.ts | 23 +++++-------------- .../OrganizationFundCampagins.tsx | 6 ++--- .../OrganizationFunds/OrganizationFunds.tsx | 2 +- 3 files changed, 9 insertions(+), 22 deletions(-) diff --git a/src/GraphQl/Queries/fundQueries.ts b/src/GraphQl/Queries/fundQueries.ts index 43530d02a8..b67252b5d0 100644 --- a/src/GraphQl/Queries/fundQueries.ts +++ b/src/GraphQl/Queries/fundQueries.ts @@ -1,14 +1,10 @@ import gql from 'graphql-tag'; /** - * GraphQL query to retrieve the list of members for a specific organization. + * GraphQL query to retrieve the list of funds for a specific organization. * - * @param id - The ID of the organization for which members are being retrieved. - * @params name - The name of the organization for which members are being retrieved. - * @params creatorId - The ID of the creator of the organization. - * @params updaterId - The ID of the user who last updated the organization. - * @params isTaxDeductible - A boolean value indicating whether the organization is tax deductible. - * @returns The list of members associated with the organization. + * @param id - The ID of the organization for which funds are being retrieved. + * @returns The list of funds associated with the organization. */ export const FUND_LIST = gql` query FundsByOrganization($input: QueryOrganizationInput!) { @@ -16,18 +12,12 @@ export const FUND_LIST = gql` funds(first: 32) { edges { node { - creator { - id - } id - isTaxDeductible name - organization { - id - } - updater { + creator { id } + createdAt } } } @@ -39,13 +29,12 @@ export const FUND_LIST = gql` * Query to fetch a specific fund by its ID, along with its associated campaigns. * @params id - The ID of the fund campaign to be fetched. * @params name - The name of the fund campaign to be fetched. - * @params sratAt - The start date of the fund campaign to be fetched. + * @params startAt - The start date of the fund campaign to be fetched. * @params endAt - The end date of the fund campaign to be fetched. * @params currencyCode - The currency code of the fund campaign to be fetched. * @params goalAmount - The goal amount of the fund campaign to be fetched. * @returns The fund campaign with the specified ID. */ - export const FUND_CAMPAIGN = gql` query GetFundById($input: QueryFundInput!) { fund(input: $input) { diff --git a/src/screens/OrganizationFundCampaign/OrganizationFundCampagins.tsx b/src/screens/OrganizationFundCampaign/OrganizationFundCampagins.tsx index 5e94deb2f9..55da2d68e3 100644 --- a/src/screens/OrganizationFundCampaign/OrganizationFundCampagins.tsx +++ b/src/screens/OrganizationFundCampaign/OrganizationFundCampagins.tsx @@ -140,14 +140,14 @@ const orgFundCampaign = (): JSX.Element => { refetch: refetchCampaign, }: { data?: { - getFundById: InterfaceQueryOrganizationFundCampaigns; + fund: InterfaceQueryOrganizationFundCampaigns; }; loading: boolean; error?: Error | undefined; refetch: () => void; } = useQuery(FUND_CAMPAIGN, { variables: { - input: { id: fundId }, // Updated to use 'input' + input: { id: fundId }, }, skip: !fundId, onCompleted: (data) => console.log('GraphQL Data Received:', data), @@ -158,8 +158,6 @@ const orgFundCampaign = (): JSX.Element => { return campaignData?.fund?.campaigns?.edges.map((edge) => edge.node) ?? []; }, [campaignData]); - console.log('compaignsData', compaignsData); - const handleClick = (campaignId: string): void => { navigate(`/fundCampaignPledge/${orgId}/${campaignId}`); }; diff --git a/src/screens/OrganizationFunds/OrganizationFunds.tsx b/src/screens/OrganizationFunds/OrganizationFunds.tsx index 7f486c9c88..d9863ee3c0 100644 --- a/src/screens/OrganizationFunds/OrganizationFunds.tsx +++ b/src/screens/OrganizationFunds/OrganizationFunds.tsx @@ -142,7 +142,7 @@ const organizationFunds = (): JSX.Element => { refetch: refetchFunds, }: { data?: { - fundsByOrganization: InterfaceFundInfo[]; + organization: InterfaceFundInfo[]; }; loading: boolean; error?: Error | undefined; From 39e2ec98220df4bc9eca783213b4aad8bacca127 Mon Sep 17 00:00:00 2001 From: Bittu kumar Date: Thu, 13 Feb 2025 22:49:21 +0530 Subject: [PATCH 06/16] Fix error --- src/GraphQl/Queries/fundQueries.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/GraphQl/Queries/fundQueries.ts b/src/GraphQl/Queries/fundQueries.ts index b67252b5d0..ce357b7258 100644 --- a/src/GraphQl/Queries/fundQueries.ts +++ b/src/GraphQl/Queries/fundQueries.ts @@ -27,12 +27,12 @@ export const FUND_LIST = gql` /** * Query to fetch a specific fund by its ID, along with its associated campaigns. - * @params id - The ID of the fund campaign to be fetched. - * @params name - The name of the fund campaign to be fetched. - * @params startAt - The start date of the fund campaign to be fetched. - * @params endAt - The end date of the fund campaign to be fetched. - * @params currencyCode - The currency code of the fund campaign to be fetched. - * @params goalAmount - The goal amount of the fund campaign to be fetched. + * @param id - The ID of the fund campaign to be fetched. + * @param name - The name of the fund campaign to be fetched. + * @param startAt - The start date of the fund campaign to be fetched. + * @param endAt - The end date of the fund campaign to be fetched. + * @param currencyCode - The currency code of the fund campaign to be fetched. + * @param goalAmount - The goal amount of the fund campaign to be fetched. * @returns The fund campaign with the specified ID. */ export const FUND_CAMPAIGN = gql` From ef6107276ae805b1d9fa7e8b4f6f1781ed8c61b9 Mon Sep 17 00:00:00 2001 From: Bittu kumar Date: Fri, 14 Feb 2025 12:37:16 +0530 Subject: [PATCH 07/16] Fix error --- src/screens/OrganizationFunds/OrganizationFunds.tsx | 8 +++++++- src/utils/interfaces.ts | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/screens/OrganizationFunds/OrganizationFunds.tsx b/src/screens/OrganizationFunds/OrganizationFunds.tsx index d9863ee3c0..888f187284 100644 --- a/src/screens/OrganizationFunds/OrganizationFunds.tsx +++ b/src/screens/OrganizationFunds/OrganizationFunds.tsx @@ -142,7 +142,13 @@ const organizationFunds = (): JSX.Element => { refetch: refetchFunds, }: { data?: { - organization: InterfaceFundInfo[]; + organization: { + funds: { + edges: { + node: InterfaceFundInfo; + }[]; + }; + }; }; loading: boolean; error?: Error | undefined; diff --git a/src/utils/interfaces.ts b/src/utils/interfaces.ts index ddb676a495..a1839b336f 100644 --- a/src/utils/interfaces.ts +++ b/src/utils/interfaces.ts @@ -1038,7 +1038,7 @@ export interface InterfaceFundInfo { isDefault: boolean; createdAt: string; organizationId: string; - creator: { _id: string; firstName: string; lastName: string }; + creator: { id: string}; } export interface InterfaceCampaignInfo { id: string; From 2b552c22fb9327450d41c49030cb03a88b5450e3 Mon Sep 17 00:00:00 2001 From: Bittu kumar Date: Fri, 14 Feb 2025 12:41:32 +0530 Subject: [PATCH 08/16] Fix error --- src/utils/interfaces.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/interfaces.ts b/src/utils/interfaces.ts index a1839b336f..81790a2ebf 100644 --- a/src/utils/interfaces.ts +++ b/src/utils/interfaces.ts @@ -1038,7 +1038,7 @@ export interface InterfaceFundInfo { isDefault: boolean; createdAt: string; organizationId: string; - creator: { id: string}; + creator: { id: string }; } export interface InterfaceCampaignInfo { id: string; From b4757106c68d91ab3905900b80dacc9d2af334c3 Mon Sep 17 00:00:00 2001 From: Bittu kumar Date: Fri, 14 Feb 2025 12:45:02 +0530 Subject: [PATCH 09/16] Fix error --- src/screens/OrganizationFundCampaign/CampaignModal.spec.tsx | 4 ++-- src/screens/OrganizationFunds/FundModal.spec.tsx | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/screens/OrganizationFundCampaign/CampaignModal.spec.tsx b/src/screens/OrganizationFundCampaign/CampaignModal.spec.tsx index f20b1ace3d..6f2a54ded9 100644 --- a/src/screens/OrganizationFundCampaign/CampaignModal.spec.tsx +++ b/src/screens/OrganizationFundCampaign/CampaignModal.spec.tsx @@ -52,7 +52,7 @@ const campaignProps: InterfaceCampaignModal[] = [ fundId: 'fundId', orgId: 'orgId', campaign: { - _id: 'campaignId1', + id: 'campaignId1', name: 'Campaign 1', fundingGoal: 100, startDate: new Date('2021-01-01'), @@ -69,7 +69,7 @@ const campaignProps: InterfaceCampaignModal[] = [ fundId: 'fundId', orgId: 'orgId', campaign: { - _id: 'campaignId1', + id: 'campaignId1', name: 'Campaign 1', fundingGoal: 100, startDate: new Date('2021-01-01'), diff --git a/src/screens/OrganizationFunds/FundModal.spec.tsx b/src/screens/OrganizationFunds/FundModal.spec.tsx index 7296f31661..5768e2bc5b 100644 --- a/src/screens/OrganizationFunds/FundModal.spec.tsx +++ b/src/screens/OrganizationFunds/FundModal.spec.tsx @@ -41,7 +41,7 @@ const fundProps: InterfaceFundModal[] = [ isOpen: true, hide: vi.fn(), fund: { - _id: 'fundId', + id: 'fundId', name: 'Fund 1', refrenceNumber: '1111', taxDeductible: true, @@ -50,7 +50,7 @@ const fundProps: InterfaceFundModal[] = [ createdAt: '2024-06-22', organizationId: 'orgId', creator: { - _id: 'creatorId1', + id: 'creatorId1', firstName: 'John', lastName: 'Doe', }, @@ -63,7 +63,7 @@ const fundProps: InterfaceFundModal[] = [ isOpen: true, hide: vi.fn(), fund: { - _id: 'fundId', + id: 'fundId', name: 'Fund 1', refrenceNumber: '1111', taxDeductible: true, From 7b9aa88f45c7bf5ddc439e3f8751c9f00638c236 Mon Sep 17 00:00:00 2001 From: Bittu kumar Date: Fri, 14 Feb 2025 13:23:54 +0530 Subject: [PATCH 10/16] Error fix --- .../CampaignModal.spec.tsx | 16 ++++++++-------- src/screens/OrganizationFunds/FundModal.spec.tsx | 6 +++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/screens/OrganizationFundCampaign/CampaignModal.spec.tsx b/src/screens/OrganizationFundCampaign/CampaignModal.spec.tsx index 6f2a54ded9..f933e5a9a0 100644 --- a/src/screens/OrganizationFundCampaign/CampaignModal.spec.tsx +++ b/src/screens/OrganizationFundCampaign/CampaignModal.spec.tsx @@ -54,10 +54,10 @@ const campaignProps: InterfaceCampaignModal[] = [ campaign: { id: 'campaignId1', name: 'Campaign 1', - fundingGoal: 100, - startDate: new Date('2021-01-01'), - endDate: new Date('2024-01-01'), - currency: 'USD', + goalAmount: 100, + startAt: new Date('2021-01-01'), + endAt: new Date('2024-01-01'), + currencyCode: 'USD', createdAt: '2021-01-01', }, refetchCampaign: vi.fn(), @@ -71,10 +71,10 @@ const campaignProps: InterfaceCampaignModal[] = [ campaign: { id: 'campaignId1', name: 'Campaign 1', - fundingGoal: 100, - startDate: new Date('2021-01-01'), - endDate: new Date('2024-01-01'), - currency: 'USD', + goalAmount: 100, + startAt: new Date('2021-01-01'), + endAt: new Date('2024-01-01'), + currencyCode: 'USD', createdAt: '2021-01-01', }, refetchCampaign: vi.fn(), diff --git a/src/screens/OrganizationFunds/FundModal.spec.tsx b/src/screens/OrganizationFunds/FundModal.spec.tsx index 5768e2bc5b..8293ba0a52 100644 --- a/src/screens/OrganizationFunds/FundModal.spec.tsx +++ b/src/screens/OrganizationFunds/FundModal.spec.tsx @@ -51,7 +51,7 @@ const fundProps: InterfaceFundModal[] = [ organizationId: 'orgId', creator: { id: 'creatorId1', - firstName: 'John', + // firstName: 'John', lastName: 'Doe', }, }, @@ -72,8 +72,8 @@ const fundProps: InterfaceFundModal[] = [ createdAt: '2024-06-22', organizationId: 'orgId', creator: { - _id: 'creatorId1', - firstName: 'John', + id: 'creatorId1', + // firstName: 'John', lastName: 'Doe', }, }, From 93f06d8a6d5afbd9c55e07bdd41550b05915f480 Mon Sep 17 00:00:00 2001 From: Bittu kumar Date: Fri, 14 Feb 2025 13:26:37 +0530 Subject: [PATCH 11/16] Error fix --- src/screens/OrganizationFunds/FundModal.spec.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/screens/OrganizationFunds/FundModal.spec.tsx b/src/screens/OrganizationFunds/FundModal.spec.tsx index 8293ba0a52..d940e7ebd0 100644 --- a/src/screens/OrganizationFunds/FundModal.spec.tsx +++ b/src/screens/OrganizationFunds/FundModal.spec.tsx @@ -52,7 +52,7 @@ const fundProps: InterfaceFundModal[] = [ creator: { id: 'creatorId1', // firstName: 'John', - lastName: 'Doe', + // lastName: 'Doe', }, }, refetchFunds: vi.fn(), @@ -74,7 +74,7 @@ const fundProps: InterfaceFundModal[] = [ creator: { id: 'creatorId1', // firstName: 'John', - lastName: 'Doe', + // lastName: 'Doe', }, }, refetchFunds: vi.fn(), From 7ef1d133d10774286ccd995086ee8cd5cec9766e Mon Sep 17 00:00:00 2001 From: Bittu kumar Date: Fri, 14 Feb 2025 14:00:46 +0530 Subject: [PATCH 12/16] Fix error --- .../CampaignModal.tsx | 5 ++-- .../OrganizationFundCampagins.tsx | 30 +++++++++---------- src/screens/OrganizationFunds/FundModal.tsx | 21 +++++-------- .../OrganizationFunds/OrganizationFunds.tsx | 4 +-- src/utils/interfaces.ts | 2 +- 5 files changed, 29 insertions(+), 33 deletions(-) diff --git a/src/screens/OrganizationFundCampaign/CampaignModal.tsx b/src/screens/OrganizationFundCampaign/CampaignModal.tsx index e159022921..6db7cbaa1e 100644 --- a/src/screens/OrganizationFundCampaign/CampaignModal.tsx +++ b/src/screens/OrganizationFundCampaign/CampaignModal.tsx @@ -62,7 +62,6 @@ const CampaignModal: React.FC = ({ isOpen, hide, fundId, - orgId, refetchCampaign, mode, campaign, @@ -107,7 +106,9 @@ const CampaignModal: React.FC = ({ * @param e - The form event. * @returns Promise */ - const createCampaignHandler = async (e: ChangeEvent) => { + const createCampaignHandler = async ( + e: ChangeEvent, + ): Promise => { e.preventDefault(); // Ensure the end date is in the future diff --git a/src/screens/OrganizationFundCampaign/OrganizationFundCampagins.tsx b/src/screens/OrganizationFundCampaign/OrganizationFundCampagins.tsx index 55da2d68e3..02337fc1aa 100644 --- a/src/screens/OrganizationFundCampaign/OrganizationFundCampagins.tsx +++ b/src/screens/OrganizationFundCampaign/OrganizationFundCampagins.tsx @@ -116,8 +116,8 @@ const orgFundCampaign = (): JSX.Element => { } const [campaign, setCampaign] = useState(null); - const [searchTerm, setSearchTerm] = useState(''); - const [sortBy, setSortBy] = useState(null); + // const [searchTerm, setSearchTerm] = useState(''); + // const [sortBy, setSortBy] = useState(null); const [modalState, setModalState] = useState(false); const [campaignModalMode, setCampaignModalMode] = useState<'edit' | 'create'>( @@ -162,11 +162,11 @@ const orgFundCampaign = (): JSX.Element => { navigate(`/fundCampaignPledge/${orgId}/${campaignId}`); }; - const { campaigns, fundName, isArchived } = useMemo(() => { + const { fundName, isArchived } = useMemo(() => { const fundName = campaignData?.fund?.name || 'Fund'; const isArchived = campaignData?.fund?.isArchived || false; - const campaigns = campaignData?.fund?.campaigns || []; - return { fundName, campaigns, isArchived }; + // const campaigns = campaignData?.fund?.campaigns || []; + return { fundName, isArchived }; }, [campaignData]); if (campaignLoading) { @@ -364,7 +364,7 @@ const orgFundCampaign = (): JSX.Element => {
@@ -376,15 +376,15 @@ const orgFundCampaign = (): JSX.Element => { { label: t('latestEndDate'), value: 'endDate_DESC' }, { label: t('earliestEndDate'), value: 'endDate_ASC' }, ]} - onSortChange={(value) => - setSortBy( - value as - | 'fundingGoal_ASC' - | 'fundingGoal_DESC' - | 'endDate_ASC' - | 'endDate_DESC', - ) - } + // onSortChange={(value) => + // setSortBy( + // value as + // | 'fundingGoal_ASC' + // | 'fundingGoal_DESC' + // | 'endDate_ASC' + // | 'endDate_DESC', + // ) + // } dataTestIdPrefix="filter" buttonLabel={tCommon('sort')} /> diff --git a/src/screens/OrganizationFunds/FundModal.tsx b/src/screens/OrganizationFunds/FundModal.tsx index 1985e912fe..effb2ff68a 100644 --- a/src/screens/OrganizationFunds/FundModal.tsx +++ b/src/screens/OrganizationFunds/FundModal.tsx @@ -80,7 +80,6 @@ const FundModal: React.FC = ({ const [formState, setFormState] = useState({ fundName: fund?.name ?? '', - fundRef: fund?.refrenceNumber ?? '', isDefault: fund?.isDefault ?? false, taxDeductible: fund?.taxDeductible ?? false, isArchived: fund?.isArchived ?? false, @@ -89,7 +88,6 @@ const FundModal: React.FC = ({ useEffect(() => { setFormState({ fundName: fund?.name ?? '', - fundRef: fund?.refrenceNumber ?? '', isDefault: fund?.isDefault ?? false, taxDeductible: fund?.taxDeductible ?? false, isArchived: fund?.isArchived ?? false, @@ -103,8 +101,7 @@ const FundModal: React.FC = ({ e: ChangeEvent, ): Promise => { e.preventDefault(); - const { fundName, fundRef, isDefault, taxDeductible, isArchived } = - formState; + const { fundName, isDefault, taxDeductible, isArchived } = formState; try { await createFund({ variables: { @@ -118,7 +115,6 @@ const FundModal: React.FC = ({ setFormState({ fundName: '', - fundRef: '', isDefault: false, taxDeductible: false, isArchived: false, @@ -157,7 +153,6 @@ const FundModal: React.FC = ({ }); setFormState({ fundName: '', - fundRef: '', isDefault: false, taxDeductible: false, isArchived: false, @@ -215,13 +210,13 @@ const FundModal: React.FC = ({ label={t('fundId')} variant="outlined" className={`${styles.noOutline} w-100`} - value={formState.fundRef} - onChange={(e) => - setFormState({ - ...formState, - fundRef: e.target.value, - }) - } + // value={formState.fundRef} + // onChange={(e) => + // setFormState({ + // ...formState, + // fundRef: e.target.value, + // }) + // } /> diff --git a/src/screens/OrganizationFunds/OrganizationFunds.tsx b/src/screens/OrganizationFunds/OrganizationFunds.tsx index 888f187284..e5eb03d3a0 100644 --- a/src/screens/OrganizationFunds/OrganizationFunds.tsx +++ b/src/screens/OrganizationFunds/OrganizationFunds.tsx @@ -116,7 +116,7 @@ const organizationFunds = (): JSX.Element => { } const [fund, setFund] = useState(null); - const [searchTerm, setSearchTerm] = useState(''); + // const [searchTerm, setSearchTerm] = useState(''); const [sortBy, setSortBy] = useState<'createdAt_ASC' | 'createdAt_DESC'>( 'createdAt_DESC', ); @@ -324,7 +324,7 @@ const organizationFunds = (): JSX.Element => {
diff --git a/src/utils/interfaces.ts b/src/utils/interfaces.ts index 81790a2ebf..7c00f5930f 100644 --- a/src/utils/interfaces.ts +++ b/src/utils/interfaces.ts @@ -1143,7 +1143,7 @@ export interface InterfaceAddress { } export interface InterfaceCreateFund { fundName: string; - fundRef: string; + // fundRef: string; isDefault: boolean; isArchived: boolean; taxDeductible: boolean; From 000bc5a7d36fa13231e6fb399494e41b95249724 Mon Sep 17 00:00:00 2001 From: Bittu kumar Date: Fri, 14 Feb 2025 21:45:12 +0530 Subject: [PATCH 13/16] Error fix --- .../OrganizationFundCampagins.tsx | 35 ++++++++++++------- .../OrganizationFunds/OrganizationFunds.tsx | 4 +-- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/screens/OrganizationFundCampaign/OrganizationFundCampagins.tsx b/src/screens/OrganizationFundCampaign/OrganizationFundCampagins.tsx index 02337fc1aa..7d93038d81 100644 --- a/src/screens/OrganizationFundCampaign/OrganizationFundCampagins.tsx +++ b/src/screens/OrganizationFundCampaign/OrganizationFundCampagins.tsx @@ -116,9 +116,9 @@ const orgFundCampaign = (): JSX.Element => { } const [campaign, setCampaign] = useState(null); - // const [searchTerm, setSearchTerm] = useState(''); - // const [sortBy, setSortBy] = useState(null); - + const [searchTerm, setSearchTerm] = useState(''); + const [sortBy, setSortBy] = useState(null); + const [modalState, setModalState] = useState(false); const [campaignModalMode, setCampaignModalMode] = useState<'edit' | 'create'>( 'create', @@ -364,7 +364,7 @@ const orgFundCampaign = (): JSX.Element => {
@@ -376,15 +376,24 @@ const orgFundCampaign = (): JSX.Element => { { label: t('latestEndDate'), value: 'endDate_DESC' }, { label: t('earliestEndDate'), value: 'endDate_ASC' }, ]} - // onSortChange={(value) => - // setSortBy( - // value as - // | 'fundingGoal_ASC' - // | 'fundingGoal_DESC' - // | 'endDate_ASC' - // | 'endDate_DESC', - // ) - // } + selectedOption={ + sortBy === 'fundingGoal_ASC' + ? tCommon('lowestGoal') + : sortBy === 'fundingGoal_DESC' + ? tCommon('highestGoal') + : sortBy === 'endDate_DESC' + ? tCommon('latestEndDate') + : tCommon('earliestEndDate') + } + onSortChange={(value) => + setSortBy( + value as + | 'fundingGoal_ASC' + | 'fundingGoal_DESC' + | 'endDate_ASC' + | 'endDate_DESC', + ) + } dataTestIdPrefix="filter" buttonLabel={tCommon('sort')} /> diff --git a/src/screens/OrganizationFunds/OrganizationFunds.tsx b/src/screens/OrganizationFunds/OrganizationFunds.tsx index e5eb03d3a0..888f187284 100644 --- a/src/screens/OrganizationFunds/OrganizationFunds.tsx +++ b/src/screens/OrganizationFunds/OrganizationFunds.tsx @@ -116,7 +116,7 @@ const organizationFunds = (): JSX.Element => { } const [fund, setFund] = useState(null); - // const [searchTerm, setSearchTerm] = useState(''); + const [searchTerm, setSearchTerm] = useState(''); const [sortBy, setSortBy] = useState<'createdAt_ASC' | 'createdAt_DESC'>( 'createdAt_DESC', ); @@ -324,7 +324,7 @@ const organizationFunds = (): JSX.Element => {
From b20bb0cf04bb0ea01adac0fd24f452628ea186d2 Mon Sep 17 00:00:00 2001 From: Bittu kumar Date: Fri, 14 Feb 2025 21:47:16 +0530 Subject: [PATCH 14/16] Error fix --- .../OrganizationFundCampaign/OrganizationFundCampagins.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/screens/OrganizationFundCampaign/OrganizationFundCampagins.tsx b/src/screens/OrganizationFundCampaign/OrganizationFundCampagins.tsx index 7d93038d81..c99ea6db3c 100644 --- a/src/screens/OrganizationFundCampaign/OrganizationFundCampagins.tsx +++ b/src/screens/OrganizationFundCampaign/OrganizationFundCampagins.tsx @@ -118,7 +118,7 @@ const orgFundCampaign = (): JSX.Element => { const [campaign, setCampaign] = useState(null); const [searchTerm, setSearchTerm] = useState(''); const [sortBy, setSortBy] = useState(null); - + const [modalState, setModalState] = useState(false); const [campaignModalMode, setCampaignModalMode] = useState<'edit' | 'create'>( 'create', From c0261f9c06d838cdb79d9ffeb2866316c751a35b Mon Sep 17 00:00:00 2001 From: Bittu kumar Date: Fri, 14 Feb 2025 22:00:27 +0530 Subject: [PATCH 15/16] Fix error --- .../OrganizationFundCampagins.tsx | 8 +++++++- src/screens/OrganizationFunds/OrganizationFunds.tsx | 9 ++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/screens/OrganizationFundCampaign/OrganizationFundCampagins.tsx b/src/screens/OrganizationFundCampaign/OrganizationFundCampagins.tsx index c99ea6db3c..e0f9122889 100644 --- a/src/screens/OrganizationFundCampaign/OrganizationFundCampagins.tsx +++ b/src/screens/OrganizationFundCampaign/OrganizationFundCampagins.tsx @@ -158,6 +158,12 @@ const orgFundCampaign = (): JSX.Element => { return campaignData?.fund?.campaigns?.edges.map((edge) => edge.node) ?? []; }, [campaignData]); + const filteredCampaigns = useMemo(() => { + return compaignsData.filter((campaign) => + campaign.name.toLowerCase().includes(searchTerm.toLowerCase()), + ); + }, [compaignsData, searchTerm]); + const handleClick = (campaignId: string): void => { navigate(`/fundCampaignPledge/${orgId}/${campaignId}`); }; @@ -431,7 +437,7 @@ const orgFundCampaign = (): JSX.Element => { } autoHeight rowHeight={65} - rows={compaignsData} + rows={filteredCampaigns} columns={columns} isRowSelectable={() => false} /> diff --git a/src/screens/OrganizationFunds/OrganizationFunds.tsx b/src/screens/OrganizationFunds/OrganizationFunds.tsx index 888f187284..2121e13188 100644 --- a/src/screens/OrganizationFunds/OrganizationFunds.tsx +++ b/src/screens/OrganizationFunds/OrganizationFunds.tsx @@ -165,6 +165,13 @@ const organizationFunds = (): JSX.Element => { return fundData?.organization?.funds?.edges.map((edge) => edge.node) ?? []; }, [fundData]); + // Write now we use the search term in client side to filter the funds + const filteredFunds = useMemo(() => { + return funds.filter((fund) => + fund.name.toLowerCase().includes(searchTerm.toLowerCase()), + ); + }, [funds, searchTerm]); + const handleClick = (fundId: string): void => { navigate(`/orgfundcampaign/${orgId}/${fundId}`); }; @@ -377,7 +384,7 @@ const organizationFunds = (): JSX.Element => { getRowClassName={() => `${styles.rowBackgrounds}`} autoHeight rowHeight={65} - rows={funds} + rows={filteredFunds} columns={columns} isRowSelectable={() => false} /> From a185ece7e649f220f9b48e417dc85249069b0854 Mon Sep 17 00:00:00 2001 From: Bittu kumar Date: Sun, 16 Feb 2025 03:39:46 +0530 Subject: [PATCH 16/16] Improve code coverage for: src\screens\OrganizationFunds\OrganizationFunds.spec.tsx --- .../OrganizationFundCampagins.tsx | 1 + .../OrganizationFunds.spec.tsx | 106 +++++++++--------- .../OrganizationFunds/OrganizationFunds.tsx | 2 +- 3 files changed, 56 insertions(+), 53 deletions(-) diff --git a/src/screens/OrganizationFundCampaign/OrganizationFundCampagins.tsx b/src/screens/OrganizationFundCampaign/OrganizationFundCampagins.tsx index e0f9122889..7442c592d8 100644 --- a/src/screens/OrganizationFundCampaign/OrganizationFundCampagins.tsx +++ b/src/screens/OrganizationFundCampaign/OrganizationFundCampagins.tsx @@ -158,6 +158,7 @@ const orgFundCampaign = (): JSX.Element => { return campaignData?.fund?.campaigns?.edges.map((edge) => edge.node) ?? []; }, [campaignData]); + // Write now we use the search term in client side to filter the campaigns, we can use the search term in the query to filter the campaigns const filteredCampaigns = useMemo(() => { return compaignsData.filter((campaign) => campaign.name.toLowerCase().includes(searchTerm.toLowerCase()), diff --git a/src/screens/OrganizationFunds/OrganizationFunds.spec.tsx b/src/screens/OrganizationFunds/OrganizationFunds.spec.tsx index aafb8e5e0a..d8841cdd7e 100644 --- a/src/screens/OrganizationFunds/OrganizationFunds.spec.tsx +++ b/src/screens/OrganizationFunds/OrganizationFunds.spec.tsx @@ -117,7 +117,17 @@ describe('OrganizationFunds Screen =>', () => { }); }); - it('open and close Create Fund modal', async () => { + it('should display error message when GraphQL query fails', async () => { + vi.mocked(useParams).mockReturnValue({ orgId: 'orgId' }); + renderOrganizationFunds(link2); + + await waitFor(() => { + expect(screen.getByTestId('errorMsg')).toBeInTheDocument(); + expect(screen.getByText('Mock graphql error')).toBeInTheDocument(); + }); + }); + + it('should open and close the Create Fund modal', async () => { vi.mocked(useParams).mockReturnValue({ orgId: 'orgId' }); renderOrganizationFunds(link1); @@ -125,70 +135,54 @@ describe('OrganizationFunds Screen =>', () => { expect(createFundBtn).toBeInTheDocument(); await userEvent.click(createFundBtn); - await waitFor(() => - expect(screen.getAllByText(translations.fundCreate)).toHaveLength(3), - ); - await userEvent.click(screen.getByTestId('fundModalCloseBtn')); - await waitFor(() => - expect(screen.queryByTestId('fundModalCloseBtn')).toBeNull(), - ); + await waitFor(() => { + expect(screen.getByText(translations.fundCreate)).toBeInTheDocument(); + }); + + const closeModalBtn = await screen.findByTestId('fundModalCloseBtn'); + await userEvent.click(closeModalBtn); + + await waitFor(() => { + expect(screen.queryByTestId('fundModalCloseBtn')).toBeNull(); + }); }); - it('open and close update fund modal', async () => { + it('should open and close the Edit Fund modal', async () => { vi.mocked(useParams).mockReturnValue({ orgId: 'orgId' }); renderOrganizationFunds(link1); + const editFundBtns = await screen.findAllByTestId('editFundBtn'); + expect(editFundBtns[0]).toBeInTheDocument(); + await userEvent.click(editFundBtns[0]); + await waitFor(() => { - expect(screen.getByTestId('searchByName')).toBeInTheDocument(); + expect(screen.getByText(translations.fundUpdate)).toBeInTheDocument(); }); - const editFundBtn = await screen.findAllByTestId('editFundBtn'); - await waitFor(() => expect(editFundBtn[0]).toBeInTheDocument()); - await userEvent.click(editFundBtn[0]); + const closeModalBtn = await screen.findByTestId('fundModalCloseBtn'); + await userEvent.click(closeModalBtn); - await waitFor(() => - expect( - screen.getAllByText(translations.fundUpdate)[0], - ).toBeInTheDocument(), - ); - await userEvent.click(screen.getByTestId('fundModalCloseBtn')); - await waitFor(() => - expect(screen.queryByTestId('fundModalCloseBtn')).toBeNull(), - ); + await waitFor(() => { + expect(screen.queryByTestId('fundModalCloseBtn')).toBeNull(); + }); }); - it('Search the Funds list by name', async () => { + it('should filter funds by search term', async () => { vi.mocked(useParams).mockReturnValue({ orgId: 'orgId' }); renderOrganizationFunds(link1); + const searchField = await screen.findByTestId('searchByName'); - fireEvent.change(searchField, { - target: { value: '2' }, - }); + fireEvent.change(searchField, { target: { value: '2' } }); fireEvent.click(screen.getByTestId('searchBtn')); + await waitFor(() => { expect(screen.getByText('Fund 2')).toBeInTheDocument(); expect(screen.queryByText('Fund 1')).toBeNull(); }); }); - it('should render the Fund screen with error', async () => { - vi.mocked(useParams).mockReturnValue({ orgId: 'orgId' }); - renderOrganizationFunds(link2); - await waitFor(() => { - expect(screen.getByTestId('errorMsg')).toBeInTheDocument(); - }); - }); - - it('renders the empty fund component', async () => { - vi.mocked(useParams).mockReturnValue({ orgId: 'orgId' }); - renderOrganizationFunds(link3); - await waitFor(() => - expect(screen.getByText(translations.noFundsFound)).toBeInTheDocument(), - ); - }); - - it('Sort the Pledges list by Latest created Date', async () => { + it('should sort funds by latest created date', async () => { vi.mocked(useParams).mockReturnValue({ orgId: 'orgId' }); renderOrganizationFunds(link1); @@ -210,7 +204,7 @@ describe('OrganizationFunds Screen =>', () => { }); }); - it('Sort the Pledges list by Earliest created Date', async () => { + it('should sort funds by earliest created date', async () => { vi.mocked(useParams).mockReturnValue({ orgId: 'orgId' }); renderOrganizationFunds(link1); @@ -232,29 +226,37 @@ describe('OrganizationFunds Screen =>', () => { }); }); - it('Click on Fund Name', async () => { + it('should navigate to campaign screen when fund name is clicked', async () => { vi.mocked(useParams).mockReturnValue({ orgId: 'orgId' }); renderOrganizationFunds(link1); - const fundName = await screen.findAllByTestId('fundName'); - expect(fundName[0]).toBeInTheDocument(); - fireEvent.click(fundName[0]); + const fundNames = await screen.findAllByTestId('fundName'); + expect(fundNames[0]).toBeInTheDocument(); + fireEvent.click(fundNames[0]); await waitFor(() => { expect(screen.getByTestId('campaignScreen')).toBeInTheDocument(); }); }); - it('Click on View Campaign', async () => { + it('should navigate to campaign screen when view button is clicked', async () => { vi.mocked(useParams).mockReturnValue({ orgId: 'orgId' }); renderOrganizationFunds(link1); - const viewBtn = await screen.findAllByTestId('viewBtn'); - expect(viewBtn[0]).toBeInTheDocument(); - fireEvent.click(viewBtn[0]); + const viewBtns = await screen.findAllByTestId('viewBtn'); + expect(viewBtns[0]).toBeInTheDocument(); + fireEvent.click(viewBtns[0]); await waitFor(() => { expect(screen.getByTestId('campaignScreen')).toBeInTheDocument(); }); }); + + it('renders the empty fund component', async () => { + vi.mocked(useParams).mockReturnValue({ orgId: 'orgId' }); + renderOrganizationFunds(link3); + await waitFor(() => + expect(screen.getByText(translations.noFundsFound)).toBeInTheDocument(), + ); + }); }); diff --git a/src/screens/OrganizationFunds/OrganizationFunds.tsx b/src/screens/OrganizationFunds/OrganizationFunds.tsx index 2121e13188..f56a0f3a00 100644 --- a/src/screens/OrganizationFunds/OrganizationFunds.tsx +++ b/src/screens/OrganizationFunds/OrganizationFunds.tsx @@ -165,7 +165,7 @@ const organizationFunds = (): JSX.Element => { return fundData?.organization?.funds?.edges.map((edge) => edge.node) ?? []; }, [fundData]); - // Write now we use the search term in client side to filter the funds + // Write now we use the search term in client side to filter the funds, we can use the search term in the query to filter the funds const filteredFunds = useMemo(() => { return funds.filter((fund) => fund.name.toLowerCase().includes(searchTerm.toLowerCase()),