-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(odd-platform-ui): owner association wip (#1622)
- Loading branch information
1 parent
938f49e
commit 445cea2
Showing
21 changed files
with
800 additions
and
310 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
138 changes: 138 additions & 0 deletions
138
...t/OwnerAssociations/OwnerAssociationsHeader/OwnerAssociationForm/OwnerAssociationForm.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,138 @@ | ||
import React from 'react'; | ||
import { Controller, useForm } from 'react-hook-form'; | ||
import { Typography } from '@mui/material'; | ||
import { useTranslation } from 'react-i18next'; | ||
import type { Collector, UserOwnerMappingFormData } from 'generated-sources'; | ||
import { registerCollector, updateCollector } from 'redux/thunks'; | ||
import { useAppDispatch, useAppSelector } from 'redux/lib/hooks'; | ||
import { | ||
getCollectorCreatingStatuses, | ||
getCollectorsUpdatingStatuses, | ||
} from 'redux/selectors'; | ||
import { | ||
Button, | ||
DialogWrapper, | ||
Input, | ||
OwnerIdAutocomplete, | ||
} from 'components/shared/elements'; | ||
import Asterisk from 'components/shared/styled-components/asterisk'; | ||
import { useCreateUserOwnerMapping } from 'lib/hooks'; | ||
|
||
interface OwnerAssociationFormProps { | ||
btnCreateEl: React.JSX.Element; | ||
} | ||
|
||
const OwnerAssociationForm: React.FC<OwnerAssociationFormProps> = ({ btnCreateEl }) => { | ||
const { t } = useTranslation(); | ||
|
||
const { | ||
mutateAsync: createUserOwnerMapping, | ||
isPending: isAssociationCreating, | ||
isSuccess, | ||
} = useCreateUserOwnerMapping(); | ||
// const dispatch = useAppDispatch(); | ||
// const { isLoading: isCollectorCreating, isLoaded: isCollectorCreated } = useAppSelector( | ||
// getCollectorCreatingStatuses | ||
// ); | ||
// const { isLoading: isCollectorUpdating, isLoaded: isCollectorUpdated } = useAppSelector( | ||
// getCollectorsUpdatingStatuses | ||
// ); | ||
|
||
const { | ||
handleSubmit, | ||
control, | ||
reset, | ||
formState: { isValid }, | ||
} = useForm<UserOwnerMappingFormData>({ | ||
mode: 'all', | ||
reValidateMode: 'onChange', | ||
defaultValues: {}, | ||
}); | ||
|
||
const clearState = () => { | ||
reset(); | ||
}; | ||
|
||
const onSubmit = async (data: UserOwnerMappingFormData) => { | ||
console.log('UserOwnerMappingFormData', data); | ||
// await createUserOwnerMapping({ | ||
// userOwnerMappingFormData: data, | ||
// }); | ||
// (collector | ||
// ? dispatch( | ||
// updateCollector({ | ||
// collectorId: collector.id, | ||
// collectorFormData: parsedData, | ||
// }) | ||
// ) | ||
// : dispatch(registerCollector({ collectorFormData: parsedData })) | ||
// ).then(() => { | ||
// clearState(); | ||
// }); | ||
}; | ||
|
||
const ownerAssociationFormTitle = ( | ||
<Typography variant='h4' component='span'> | ||
Create association | ||
</Typography> | ||
); | ||
|
||
const ownerAssociationFormContent = () => ( | ||
<form id='owner-association-create-form' onSubmit={handleSubmit(onSubmit)}> | ||
<Typography variant='subtitle2' fontSize='0.73rem' sx={{ mb: 1.5 }}> | ||
{t('Fields with the')} <Asterisk>*</Asterisk> | ||
{' symbol are required to save the Association'} | ||
</Typography> | ||
<Controller | ||
name='ownerId' | ||
control={control} | ||
rules={{ required: true }} | ||
render={({ field }) => <OwnerIdAutocomplete field={field} />} | ||
/> | ||
<Controller | ||
name='oidcUsername' | ||
control={control} | ||
render={({ field }) => ( | ||
<Input {...field} variant='main-m' sx={{ my: 1.5 }} label='User' /> | ||
)} | ||
/> | ||
<Controller | ||
name='provider' | ||
control={control} | ||
rules={{ required: false }} | ||
render={({ field }) => ( | ||
// <OwnerAutocomplete field={field} disableOwnerCreating={!createOwner} /> | ||
<div>provider autocomplete</div> | ||
)} | ||
/> | ||
</form> | ||
); | ||
|
||
const ownerAssociationFormActionButtons = () => ( | ||
<Button | ||
text={t('Save')} | ||
type='submit' | ||
form='owner-association-create-form' | ||
buttonType='main-lg' | ||
fullWidth | ||
disabled={!isValid} | ||
/> | ||
); | ||
|
||
return ( | ||
<DialogWrapper | ||
renderOpenBtn={({ handleOpen }) => | ||
React.cloneElement(btnCreateEl, { onClick: handleOpen }) | ||
} | ||
title={ownerAssociationFormTitle} | ||
renderContent={ownerAssociationFormContent} | ||
renderActions={ownerAssociationFormActionButtons} | ||
handleCloseSubmittedForm={isSuccess} | ||
isLoading={isAssociationCreating} | ||
clearState={clearState} | ||
confirmOnClose | ||
/> | ||
); | ||
}; | ||
|
||
export default OwnerAssociationForm; |
55 changes: 18 additions & 37 deletions
55
...mponents/Management/OwnerAssociations/OwnerAssociationsHeader/OwnerAssociationsHeader.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
66 changes: 66 additions & 0 deletions
66
...iationsList/OwnerAssociationsActive/ActiveAssociationRequest/ActiveAssociationRequest.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,66 @@ | ||
import React from 'react'; | ||
import { Grid, Typography } from '@mui/material'; | ||
import type { OwnerAssociationRequest } from 'generated-sources'; | ||
import { useAppDateTime } from 'lib/hooks'; | ||
import * as S from '../../OwnerAssociationsSharedStyles'; | ||
|
||
interface ActiveAssociationRequestProps { | ||
ownerName: OwnerAssociationRequest['ownerName']; | ||
username: OwnerAssociationRequest['username']; | ||
provider?: OwnerAssociationRequest['provider']; | ||
// TODO: fix type | ||
role?: string; | ||
statusUpdatedBy: OwnerAssociationRequest['statusUpdatedBy']; | ||
statusUpdatedAt: OwnerAssociationRequest['statusUpdatedAt']; | ||
} | ||
|
||
const ActiveAssociationRequest: React.FC<ActiveAssociationRequestProps> = ({ | ||
provider, | ||
username, | ||
role, | ||
statusUpdatedBy, | ||
statusUpdatedAt, | ||
ownerName, | ||
}) => { | ||
const { associationRequestFormattedDateTime } = useAppDateTime(); | ||
|
||
return ( | ||
<S.AssociationsItemContainer container> | ||
<Grid item lg={2.5}> | ||
<Typography variant='body1' noWrap title={username}> | ||
{username} | ||
</Typography> | ||
</Grid> | ||
<Grid item lg={2.5}> | ||
<Typography variant='body1' noWrap title={ownerName}> | ||
{ownerName} | ||
</Typography> | ||
</Grid> | ||
<Grid item lg={1}> | ||
{role} | ||
</Grid> | ||
<Grid item lg={2}> | ||
<Typography variant='body1' noWrap title={provider}> | ||
{provider} | ||
</Typography> | ||
</Grid> | ||
<Grid item lg={2}> | ||
<Typography | ||
variant='body1' | ||
noWrap | ||
title={statusUpdatedBy?.owner?.name || statusUpdatedBy?.identity.username} | ||
> | ||
{statusUpdatedBy?.owner?.name || statusUpdatedBy?.identity.username} | ||
</Typography> | ||
</Grid> | ||
<Grid item lg={2}> | ||
<Typography variant='body1' noWrap> | ||
{statusUpdatedAt && | ||
associationRequestFormattedDateTime(statusUpdatedAt?.getTime())} | ||
</Typography> | ||
</Grid> | ||
</S.AssociationsItemContainer> | ||
); | ||
}; | ||
|
||
export default ActiveAssociationRequest; |
Oops, something went wrong.