Skip to content

Commit

Permalink
Merge pull request #239 from chain4travel/aeddaqqa/partner-config-v2
Browse files Browse the repository at this point in the history
fix(partnerConfig): adjustment of styling and text modifications
  • Loading branch information
aeddaqqa authored Sep 24, 2024
2 parents 0bcbe0f + c2cf5ac commit 2c9a8c2
Show file tree
Hide file tree
Showing 12 changed files with 575 additions and 320 deletions.
131 changes: 71 additions & 60 deletions src/components/Input.tsx
Original file line number Diff line number Diff line change
@@ -1,83 +1,94 @@
import { InputAdornment, OutlinedInput, Typography } from '@mui/material'
import React, { useMemo } from 'react'
import { actionTypes, usePartnerConfigurationContext } from '../helpers/partnerConfigurationContext'
import useWalletBalance from '../helpers/useWalletBalance'

const Input = ({ ...rest }) => {
const { state, dispatch } = usePartnerConfigurationContext()
const error = useMemo(() => {
if (!state.balance) return true
let balance = parseFloat(state.balance)
return balance < 100
}, [state])

const { balance: maxBalance } = useWalletBalance()
const handleChange = e => {
const newAmount = e.target.value
if (newAmount === '' || /^\d*\.?\d*$/.test(newAmount)) {
dispatch({
type: actionTypes.UPDATE_BALANCE,
payload: {
newValue: e.target.value,
newValue: newAmount,
},
})
}
}
const error = useMemo(() => {
if (!state.balance) return true
let balance = parseFloat(state.balance)
return balance < 100 || balance > parseFloat(maxBalance) - 0.5
}, [state, maxBalance])

return (
<OutlinedInput
value={state.balance}
onChange={handleChange}
error={error}
inputProps={{
inputMode: 'decimal',
pattern: '[0-9]*',
}}
startAdornment={
<InputAdornment
position="start"
sx={{
width: 'fit-content',
color: theme => theme.palette.text.primary,
}}
>
<Typography variant="body2">Prefund Amount:</Typography>
</InputAdornment>
}
endAdornment={
error ? (
<InputAdornment position="end" sx={{ width: 'fit-content' }}>
<svg
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M12 2C17.53 2 22 6.47 22 12C22 17.53 17.53 22 12 22C6.47 22 2 17.53 2 12C2 6.47 6.47 2 12 2ZM15.59 7L12 10.59L8.41 7L7 8.41L10.59 12L7 15.59L8.41 17L12 13.41L15.59 17L17 15.59L13.41 12L17 8.41L15.59 7Z"
fill="#E5431F"
/>
</svg>
</InputAdornment>
) : (
<InputAdornment position="end" sx={{ width: 'fit-content' }}>
<svg
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M12 2C6.5 2 2 6.5 2 12C2 17.5 6.5 22 12 22C17.5 22 22 17.5 22 12C22 6.5 17.5 2 12 2ZM10 17L5 12L6.41 10.59L10 14.17L17.59 6.58L19 8L10 17Z"
fill="#18B728"
/>
</svg>
<>
<OutlinedInput
value={state.balance}
onChange={handleChange}
error={error}
inputProps={{
inputMode: 'decimal',
pattern: '[0-9]*',
}}
startAdornment={
<InputAdornment
position="start"
sx={{
width: 'fit-content',
color: theme => theme.palette.text.primary,
}}
>
<Typography variant="body2">Prefund Amount:</Typography>
</InputAdornment>
)
}
{...rest}
/>
}
endAdornment={
error ? (
<InputAdornment position="end" sx={{ width: 'fit-content' }}>
<svg
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M12 2C17.53 2 22 6.47 22 12C22 17.53 17.53 22 12 22C6.47 22 2 17.53 2 12C2 6.47 6.47 2 12 2ZM15.59 7L12 10.59L8.41 7L7 8.41L10.59 12L7 15.59L8.41 17L12 13.41L15.59 17L17 15.59L13.41 12L17 8.41L15.59 7Z"
fill="#E5431F"
/>
</svg>
</InputAdornment>
) : (
<InputAdornment position="end" sx={{ width: 'fit-content' }}>
<svg
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M12 2C6.5 2 2 6.5 2 12C2 17.5 6.5 22 12 22C17.5 22 22 17.5 22 12C22 6.5 17.5 2 12 2ZM10 17L5 12L6.41 10.59L10 14.17L17.59 6.58L19 8L10 17Z"
fill="#18B728"
/>
</svg>
</InputAdornment>
)
}
{...rest}
/>
{error && (
<Typography variant="caption" color="error">
{parseFloat(state.balance) < 100 || !state.balance || state.balance === '0'
? 'Balance must be at least 100'
: `Balance cannot exceed ${parseFloat(maxBalance) - 0.5}`}
</Typography>
)}
</>
)
}

export default Input
//8 279.81669975
23 changes: 21 additions & 2 deletions src/components/Partners/UpdatedSelectComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
import { Autocomplete, TextField, Typography } from '@mui/material'
import React, { useMemo } from 'react'
import React, { useMemo, useState } from 'react'

const UpdatedSelectComponent = React.memo(
({ editing = true, supplierState, dispatchSupplierState, actionTypes }) => {
const [value, setValue] = useState(null)
const [inputValue, setInputValue] = useState('')

const handleChange = (event, newValue) => {
if (newValue) {
addService(newValue)
setValue(null)
setInputValue('')
}
}

const handleInputChange = (event, newInputValue) => {
setInputValue(newInputValue)
}

const addService = service => {
if (
!supplierState.stepsConfig[supplierState.step].services.find(
Expand Down Expand Up @@ -60,6 +69,10 @@ const UpdatedSelectComponent = React.memo(
<Autocomplete
disabled={!editing}
options={options}
value={value}
inputValue={inputValue}
onInputChange={handleInputChange}
onChange={handleChange}
renderInput={params => (
<TextField
{...params}
Expand All @@ -75,7 +88,6 @@ const UpdatedSelectComponent = React.memo(
{option}
</Typography>
)}
onChange={handleChange}
filterOptions={(options, { inputValue }) =>
options.filter(option =>
option.toLowerCase().includes(inputValue.toLowerCase()),
Expand Down Expand Up @@ -106,6 +118,13 @@ const UpdatedSelectComponent = React.memo(
borderColor: theme => theme.palette.card.border,
borderRadius: '12px',
},
'& input': {
color: 'white',
},
'& input::placeholder': {
color: 'white',
opacity: 1,
},
},
'& .MuiAutocomplete-input': {
padding: '0 !important',
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/partnerConfigurationContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const initialState = {
stepsConfig: [
{
step: 0,
title: 'Messenger configuration',
title: 'Create Messenger Account',
services: [],
paragraph:
'This wizard will help you create and activate your Camino Messenger Account with Camino Messenger address. Once set up, your Camino Messenger address will be displayed on your partner detail page, enabling direct communication with other Camino Messenger users.',
Expand Down
52 changes: 27 additions & 25 deletions src/layout/PartnersLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { Box, Link, Toolbar, Typography } from '@mui/material'
import { Box, Button, Link, Toolbar, Typography } from '@mui/material'

import { Paper } from '@mui/material'
import { ethers } from 'ethers'
import React, { useEffect } from 'react'
import { Navigate, Outlet, useNavigate, useParams } from 'react-router'
import store from 'wallet/store'
import CMAccount from '../helpers/CMAccountManagerModule#CMAccount.json'
import { PartnerConfigurationProvider } from '../helpers/partnerConfigurationContext'
import { SmartContractProvider } from '../helpers/useSmartContract'
import { useAppSelector } from '../hooks/reduxHooks'
Expand All @@ -15,6 +13,15 @@ import { getActiveNetwork } from '../redux/slices/network'
import Links from '../views/settings/Links'

const ClaimProfile = () => {
const generateEmail = () => {
const subject = 'Claim a Partner'
const body = `This is to claim a Partner record and associate it to the wallet with C-Chain address .Please add your name, contact details, the Partner name, and attach any evidence of your affiliation with the Partner.`

const mailtoLink = `mailto:${emailAddress}?subject=${encodeURIComponent(
subject,
)}&body=${encodeURIComponent(body)}`
window.location.href = mailtoLink
}
const emailAddress = '[email protected]'
return (
<Box
Expand All @@ -29,36 +36,31 @@ const ClaimProfile = () => {
>
<Typography variant="h5">Claim a profile</Typography>
<Typography variant="body2" textAlign={'center'}>
To manage and configure your Camino Messenger, you need to claim an account.
To manage and configure your Camino Messenger, you need to claim a Partner record
first.
</Typography>
<Typography variant="body2" textAlign={'center'}>
Contact the Camino Network Foundation via{' '}
<Link href={`mailto:${emailAddress}`} target="_blank" rel="noopener noreferrer">
email
</Link>{' '}
Contact the Camino Network Foundation via <Link onClick={generateEmail}>email</Link>{' '}
to proceed.
</Typography>
<Button
onClick={generateEmail}
sx={{
padding: '10px 16px',
borderRadius: '8px',
background: 'linear-gradient(90deg, #0085FF 0%, #B440FC 100%)',
backgroundColor: theme =>
theme.palette.mode === 'dark' ? '#020617' : '#F1F5F9',
}}
>
<Typography fontSize={14} fontWeight={600} lineHeight={'20px'}>
Contact
</Typography>
</Button>
</Box>
)
}

// Function to create a contract instance
function getPartnerContract(address, provider) {
return new ethers.Contract(address, CMAccount, provider)
}

// Main function to get services from multiple partner contracts
// async function getPartnerServices(partnerAddresses: string[], providerUrl: string) {
// const provider = new ethers.JsonRpcProvider(providerUrl)
// for (const address of partnerAddresses) {
// const contract = getPartnerContract(address, provider)
// try {
// const result = await contract.getSupportedServices()
// console.log(result)
// } catch (error) {}
// }
// }

const PartnersLayout = () => {
const path = window.location.pathname
const { data, isLoading } = useIsPartnerQuery({
Expand Down
27 changes: 12 additions & 15 deletions src/views/partners/ConfigurDistrubitor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ import {
} from '../../helpers/partnerConfigurationContext'
import { usePartnerConfig } from '../../helpers/usePartnerConfig'
import { useSmartContract } from '../../helpers/useSmartContract'
import { useAppDispatch } from '../../hooks/reduxHooks'
import { useFetchPartnerDataQuery } from '../../redux/services/partners'
import { updateNotificationStatus } from '../../redux/slices/app-config'
import { Configuration } from './Configuration'

function ServiceChangesPreview({ added, removed }) {
Expand Down Expand Up @@ -176,12 +178,6 @@ export const BasicWantedServices = () => {
</Box>
<Divider />
</Configuration>
<Box sx={{ display: 'flex', flexDirection: 'column', gap: '16px' }}>
<Configuration.Infos
information="This Camino Messenger wizard will assist you in generating and activating your Camino Messenger address. Once the process is complete, your Camino Messenger address will appear on your partner detail page, allowing you to communicate directly with other Camino Messenger accounts."
rackRates="This Camino Messenger wizard will assist you in generating and activating your Camino Messenger address."
></Configuration.Infos>
</Box>
</Box>
)
}
Expand Down Expand Up @@ -246,6 +242,7 @@ const ConfigurDistrubitor = () => {
setRemoved(removed)
}, [compareServices])

const appDispatch = useAppDispatch()
async function confirmEditing() {
setLoading(true)
await removeWantedServices(removed.map(elem => elem.name))
Expand All @@ -255,6 +252,12 @@ const ConfigurDistrubitor = () => {
type: actionTypes.UPDATE_WANTED_SERVICES,
payload: { wantedServices: res },
})
appDispatch(
updateNotificationStatus({
message: 'Services configured successfully',
severity: 'success',
}),
)
setAdded([])
setRemoved([])
setLoading(false)
Expand Down Expand Up @@ -325,7 +328,7 @@ const ConfigurDistrubitor = () => {
setEditing(true)
}}
>
Edit configuration
Configure Services
</MainButton>
) : (
<>
Expand All @@ -336,7 +339,7 @@ const ConfigurDistrubitor = () => {
cancelEditing()
}}
>
Cancel Editing
Cancel
</MainButton>
<MainButton
loading={loading}
Expand All @@ -345,18 +348,12 @@ const ConfigurDistrubitor = () => {
confirmEditing()
}}
>
Confirm Editing
Save Changes
</MainButton>
</>
)}
</Configuration.Buttons>
</Configuration>
<Box sx={{ display: 'flex', flexDirection: 'column', gap: '16px' }}>
<Configuration.Infos
information="This Camino Messenger wizard will assist you in generating and activating your Camino Messenger address. Once the process is complete, your Camino Messenger address will appear on your partner detail page, allowing you to communicate directly with other Camino Messenger accounts."
rackRates="This Camino Messenger wizard will assist you in generating and activating your Camino Messenger address."
></Configuration.Infos>
</Box>
</Box>
)
}
Expand Down
Loading

0 comments on commit 2c9a8c2

Please sign in to comment.