-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DASH-130 Add Admin Partner profile creation page
- Loading branch information
1 parent
8c93468
commit f4013d3
Showing
27 changed files
with
1,096 additions
and
8 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
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
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
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
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
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
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
43 changes: 43 additions & 0 deletions
43
client/src/pages/AdminPartnersListPage/AdminPartnersListPage.module.scss
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,43 @@ | ||
@import '../../assets/styles/colors.scss'; | ||
@import '../../assets/styles/fontMixins.scss'; | ||
|
||
.tableContainer { | ||
width: auto; | ||
margin-top: 30px; | ||
|
||
th { | ||
text-align: center; | ||
vertical-align: middle; | ||
} | ||
|
||
.userItem { cursor: pointer } | ||
} | ||
|
||
.label { | ||
margin-bottom: 1rem; | ||
font-size: 0.875em; | ||
color: $dark-jungle-green; | ||
@include sf-pro-display-medium; | ||
} | ||
|
||
.button { | ||
line-height: 1; | ||
} | ||
|
||
.imageContainer { | ||
> div { | ||
padding: 0 20px; | ||
} | ||
.previewImage { | ||
max-width: 380px; | ||
max-height: 115px; | ||
width: 100%; | ||
} | ||
} | ||
|
||
.landingTextsContainer { | ||
padding: 10px; | ||
background-color: $gallery; | ||
border-radius: 7px; | ||
box-shadow: 0 0 8px 0 rgba($black, 0.11); | ||
} |
135 changes: 135 additions & 0 deletions
135
client/src/pages/AdminPartnersListPage/AdminPartnersListPage.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,135 @@ | ||
import React, { useState, useCallback } from 'react'; | ||
import { Button, Table } from 'react-bootstrap'; | ||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; | ||
|
||
import Loader from '../../components/Loader/Loader'; | ||
import { PartnerModal } from './components/updatePartner/PartnerModal'; | ||
|
||
import { formatDateToLocale } from '../../helpers/stringFormatters'; | ||
import usePagination from '../../hooks/usePagination'; | ||
import apis from '../../api'; | ||
import { log } from '../../util/general'; | ||
|
||
import { Props } from './types'; | ||
import { RefProfile } from '../../types'; | ||
|
||
import classes from './AdminPartnersListPage.module.scss'; | ||
|
||
const AdminPartnersListPage: React.FC<Props> = props => { | ||
const { loading, partnersList, getPartnersList } = props; | ||
const [showPartnerModal, setShowPartnerModal] = useState<boolean>(false); | ||
const [selectedPartner, setSelectedPartner] = useState<RefProfile>(null); | ||
const [partnerActionLoading, setPartnerActionLoading] = useState<boolean>( | ||
false, | ||
); | ||
|
||
const { paginationComponent, refresh } = usePagination(getPartnersList); | ||
|
||
const onAddPartner = useCallback(() => { | ||
setShowPartnerModal(true); | ||
}, []); | ||
const onEditPartner = useCallback((partner: RefProfile) => { | ||
if (partner.settings?.actions?.SIGNNFT) { | ||
partner.settings.actions.SIGNNFT.enabled = true; | ||
} | ||
if (partner.settings?.actions?.REG) { | ||
partner.settings.actions.REG.enabled = true; | ||
} | ||
if ( | ||
partner.settings?.domains.length && | ||
!partner.settings.domains.includes(partner.settings.preselectedDomain) | ||
) { | ||
partner.settings.preselectedDomain = partner.settings.domains[0]; | ||
} else { | ||
partner.settings.preselectedDomain = null; | ||
} | ||
setSelectedPartner(partner); | ||
setShowPartnerModal(true); | ||
}, []); | ||
const closeModal = useCallback(() => { | ||
setShowPartnerModal(false); | ||
setSelectedPartner(null); | ||
}, []); | ||
const savePartner = useCallback( | ||
async (partner: RefProfile) => { | ||
setPartnerActionLoading(true); | ||
try { | ||
if (partner.settings?.actions) { | ||
if (!partner.settings.actions.SIGNNFT?.enabled) { | ||
delete partner.settings.actions.SIGNNFT; | ||
} | ||
if (!partner.settings.actions.REG?.enabled) { | ||
delete partner.settings.actions.REG; | ||
} | ||
} | ||
if (partner.id) { | ||
await apis.admin.editPartner(partner); | ||
} else { | ||
await apis.admin.createPartner(partner); | ||
} | ||
await refresh(); | ||
closeModal(); | ||
} catch (err) { | ||
log.error(err); | ||
} finally { | ||
setPartnerActionLoading(false); | ||
} | ||
}, | ||
[refresh, closeModal], | ||
); | ||
|
||
return ( | ||
<> | ||
<div className={classes.tableContainer}> | ||
<Button className="mb-4" onClick={onAddPartner}> | ||
<FontAwesomeIcon icon="plus-square" className="mr-2" /> Add New | ||
Partner | ||
</Button> | ||
<Table className="table" striped={true}> | ||
<thead> | ||
<tr> | ||
<th scope="col">#</th> | ||
<th scope="col">Name</th> | ||
<th scope="col">Referral Code</th> | ||
<th scope="col">Created</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{partnersList?.length | ||
? partnersList.map((partner, i) => ( | ||
<tr | ||
key={partner.id} | ||
className={classes.userItem} | ||
onClick={() => onEditPartner(partner)} | ||
> | ||
<th>{i + 1}</th> | ||
<th>{partner.label}</th> | ||
<th>{partner.code}</th> | ||
<th> | ||
{partner.createdAt | ||
? formatDateToLocale(partner.createdAt) | ||
: null} | ||
</th> | ||
</tr> | ||
)) | ||
: null} | ||
</tbody> | ||
</Table> | ||
|
||
{paginationComponent} | ||
|
||
{loading && <Loader />} | ||
</div> | ||
|
||
<PartnerModal | ||
initialValues={selectedPartner} | ||
show={showPartnerModal} | ||
onSubmit={savePartner} | ||
loading={partnerActionLoading} | ||
onClose={closeModal} | ||
/> | ||
</> | ||
); | ||
}; | ||
|
||
export default AdminPartnersListPage; |
32 changes: 32 additions & 0 deletions
32
client/src/pages/AdminPartnersListPage/components/updatePartner/PartnerForm.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,32 @@ | ||
import React from 'react'; | ||
import { Form } from 'react-final-form'; | ||
import arrayMutators from 'final-form-arrays'; | ||
|
||
import { PartnerFormComponent } from './PartnerFormComponent'; | ||
|
||
import { validate } from './validation'; | ||
|
||
import { RefProfile } from '../../../../types'; | ||
|
||
type Props = { | ||
onSubmit: (values: RefProfile) => Promise<void>; | ||
loading: boolean; | ||
initialValues?: RefProfile; | ||
}; | ||
|
||
export const PartnerForm: React.FC<Props> = props => { | ||
const { onSubmit, loading, initialValues } = props; | ||
|
||
return ( | ||
<Form | ||
onSubmit={onSubmit} | ||
initialValues={initialValues} | ||
component={PartnerFormComponent} | ||
loading={loading} | ||
validate={validate} | ||
mutators={{ | ||
...arrayMutators, | ||
}} | ||
/> | ||
); | ||
}; |
Oops, something went wrong.