-
Notifications
You must be signed in to change notification settings - Fork 412
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
get value from image Signed-off-by: Tiago Fonseca <[email protected]> fix Signed-off-by: Tiago Fonseca <[email protected]> addressing comments addressing comments
- Loading branch information
1 parent
2e79ff4
commit 4d88538
Showing
6 changed files
with
183 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { Res } from 'common/types/responses' | ||
import { Req } from 'common/types/requests' | ||
import { service } from 'common/service' | ||
|
||
export const organisationLicensingService = service | ||
.enhanceEndpoints({ addTagTypes: ['OrganisationLicensing'] }) | ||
.injectEndpoints({ | ||
endpoints: (builder) => ({ | ||
uploadOrganisationLicence: builder.mutation< | ||
Res['organisationLicence'], | ||
Req['uploadOrganisationLicence'] | ||
>({ | ||
query: (query: Req['uploadOrganisationLicence']) => { | ||
const formData = new FormData() | ||
formData.append('licence_signature', query.body.licence_signature) | ||
formData.append('licence', query.body.licence) | ||
return { | ||
body: formData, | ||
method: 'PUT', | ||
url: `organisations/${query.id}/licence`, | ||
} | ||
}, | ||
}), | ||
// END OF ENDPOINTS | ||
}), | ||
}) | ||
|
||
export async function uploadOrganisationLicence( | ||
store: any, | ||
data: Req['uploadOrganisationLicence'], | ||
options?: Parameters< | ||
typeof organisationLicensingService.endpoints.uploadOrganisationLicence.initiate | ||
>[1], | ||
) { | ||
store.dispatch( | ||
organisationLicensingService.endpoints.uploadOrganisationLicence.initiate( | ||
data, | ||
options, | ||
), | ||
) | ||
return Promise.all( | ||
store.dispatch(organisationLicensingService.util.getRunningQueriesThunk()), | ||
) | ||
} | ||
// END OF FUNCTION_EXPORTS | ||
|
||
export const { | ||
useUploadOrganisationLicenceMutation, | ||
// END OF EXPORTS | ||
} = organisationLicensingService |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import { useUploadOrganisationLicenceMutation } from 'common/services/useOrganisationLicensing' | ||
import React, { useEffect, useRef, useState } from 'react' | ||
import Button from './base/forms/Button' | ||
import Utils from 'common/utils/utils' | ||
|
||
type LicensingTabContentProps = { | ||
organisationId: number | ||
} | ||
|
||
const LicensingTabContent: React.FC<LicensingTabContentProps> = ({ | ||
organisationId, | ||
}) => { | ||
const [uploadOrganisationLicence, { error, isLoading, isSuccess }] = | ||
useUploadOrganisationLicenceMutation() | ||
|
||
const [licence, setLicence] = useState<File | null>(null) | ||
const [licenceSignature, setLicenceSignature] = useState<File | null>(null) | ||
|
||
const licenceInputRef = useRef<HTMLInputElement>(null) | ||
const licenceSignatureInputRef = useRef<HTMLInputElement>(null) | ||
|
||
useEffect(() => { | ||
if (isSuccess) { | ||
toast('Licence uploaded successfully') | ||
} | ||
|
||
if (!isSuccess && error?.data) { | ||
toast( | ||
Array.isArray(error?.data) | ||
? error?.data[0] | ||
: 'Upload was not successful', | ||
'danger', | ||
) | ||
} | ||
}, [isSuccess, error]) | ||
|
||
const handleUpload = () => { | ||
if (!licence || !licenceSignature) return | ||
uploadOrganisationLicence({ | ||
body: { licence, licence_signature: licenceSignature }, | ||
id: organisationId, | ||
}) | ||
} | ||
|
||
return ( | ||
<div className='mt-4'> | ||
<h5 className='mb-5'>Upload Licensing Files</h5> | ||
<form | ||
className='upload-licensing-tab' | ||
onSubmit={(e) => { | ||
Utils.preventDefault(e) | ||
handleUpload() | ||
}} | ||
> | ||
<FormGroup> | ||
<input | ||
type='file' | ||
ref={licenceInputRef} | ||
style={{ display: 'none' }} | ||
onChange={() => | ||
setLicence(licenceInputRef.current?.files?.[0] ?? null) | ||
} | ||
/> | ||
<input | ||
type='file' | ||
ref={licenceSignatureInputRef} | ||
style={{ display: 'none' }} | ||
onChange={() => | ||
setLicenceSignature( | ||
licenceSignatureInputRef.current?.files?.[0] ?? null, | ||
) | ||
} | ||
/> | ||
<div className='flex-row'> | ||
<Button onClick={() => licenceInputRef.current?.click()}> | ||
Select Licence File | ||
</Button> | ||
{!!licence?.name && ( | ||
<p className='mt-auto mb-auto ml-2 fs-small lh-sm'> | ||
{licence.name} | ||
</p> | ||
)} | ||
</div> | ||
<div className='flex-row mt-4'> | ||
<Button onClick={() => licenceSignatureInputRef.current?.click()}> | ||
Select Signature File | ||
</Button> | ||
{!!licenceSignature?.name && ( | ||
<p className='mt-auto mb-auto ml-2 fs-small lh-sm'> | ||
{licenceSignature.name} | ||
</p> | ||
)} | ||
</div> | ||
<div className='text-right'> | ||
<Button | ||
type='submit' | ||
data-test='create-feature-btn' | ||
id='create-feature-btn' | ||
disabled={!licence || !licenceSignature} | ||
> | ||
{isLoading ? 'Uploading' : 'Upload Licensing Files'} | ||
</Button> | ||
</div> | ||
</FormGroup> | ||
</form> | ||
</div> | ||
) | ||
} | ||
|
||
export default LicensingTabContent |
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