feat: Update certificate upload process to use signed URLs and enable fields for new certificates

This commit is contained in:
Achintha Isuru
2026-03-01 20:28:13 -05:00
parent e0e7bd51ce
commit 5795f7c45d
2 changed files with 13 additions and 15 deletions

View File

@@ -46,24 +46,20 @@ class CertificatesRepositoryImpl implements CertificatesRepository {
// 2. Generate a signed URL for verification service to access the file // 2. Generate a signed URL for verification service to access the file
// Wait, verification service might need this or just the URI. // Wait, verification service might need this or just the URI.
// Following DocumentRepository behavior: // Following DocumentRepository behavior:
await _signedUrlService.createSignedUrl(fileUri: uploadRes.fileUri); final SignedUrlResponse signedUrlRes = await _signedUrlService.createSignedUrl(fileUri: uploadRes.fileUri);
// 3. Initiate verification // 3. Initiate verification
final List<domain.StaffCertificate> allCerts = await getCertificates();
final domain.StaffCertificate currentCert = allCerts.firstWhere(
(domain.StaffCertificate c) => c.certificationType == certificationType,
);
final String staffId = await _service.getStaffId(); final String staffId = await _service.getStaffId();
final VerificationResponse verificationRes = await _verificationService final VerificationResponse verificationRes = await _verificationService
.createVerification( .createVerification(
fileUri: uploadRes.fileUri, fileUri: uploadRes.fileUri,
type: certificationType.value, type: 'certification',
category: 'certification',
subjectType: 'worker', subjectType: 'worker',
subjectId: staffId, subjectId: staffId,
rules: <String, dynamic>{ rules: <String, dynamic>{
'certificateDescription': currentCert.description, 'certificateName': name,
'certificateIssuer': issuer,
'certificateNumber': certificateNumber,
}, },
); );
@@ -72,7 +68,7 @@ class CertificatesRepositoryImpl implements CertificatesRepository {
certificationType: certificationType, certificationType: certificationType,
name: name, name: name,
status: domain.StaffCertificateStatus.pending, status: domain.StaffCertificateStatus.pending,
fileUrl: uploadRes.fileUri, fileUrl: signedUrlRes.signedUrl,
expiry: expiryDate, expiry: expiryDate,
issuer: issuer, issuer: issuer,
certificateNumber: certificateNumber, certificateNumber: certificateNumber,

View File

@@ -35,6 +35,8 @@ class _CertificateUploadPageState extends State<CertificateUploadPage> {
final FilePickerService _filePicker = Modular.get<FilePickerService>(); final FilePickerService _filePicker = Modular.get<FilePickerService>();
bool get _isNewCertificate => widget.certificate == null;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
@@ -145,8 +147,8 @@ class _CertificateUploadPageState extends State<CertificateUploadPage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BlocProvider<CertificateUploadCubit>( return BlocProvider<CertificateUploadCubit>.value(
create: (BuildContext _) => Modular.get<CertificateUploadCubit>(), value: Modular.get<CertificateUploadCubit>(),
child: BlocConsumer<CertificateUploadCubit, CertificateUploadState>( child: BlocConsumer<CertificateUploadCubit, CertificateUploadState>(
listener: (BuildContext context, CertificateUploadState state) { listener: (BuildContext context, CertificateUploadState state) {
if (state.status == CertificateUploadStatus.success) { if (state.status == CertificateUploadStatus.success) {
@@ -190,7 +192,7 @@ class _CertificateUploadPageState extends State<CertificateUploadPage> {
const SizedBox(height: UiConstants.space2), const SizedBox(height: UiConstants.space2),
TextField( TextField(
controller: _nameController, controller: _nameController,
enabled: false, enabled: _isNewCertificate,
decoration: InputDecoration( decoration: InputDecoration(
hintText: t.staff_certificates.upload_modal.name_hint, hintText: t.staff_certificates.upload_modal.name_hint,
border: OutlineInputBorder( border: OutlineInputBorder(
@@ -208,7 +210,7 @@ class _CertificateUploadPageState extends State<CertificateUploadPage> {
const SizedBox(height: UiConstants.space2), const SizedBox(height: UiConstants.space2),
TextField( TextField(
controller: _issuerController, controller: _issuerController,
enabled: false, enabled: _isNewCertificate,
decoration: InputDecoration( decoration: InputDecoration(
hintText: t.staff_certificates.upload_modal.issuer_hint, hintText: t.staff_certificates.upload_modal.issuer_hint,
border: OutlineInputBorder( border: OutlineInputBorder(
@@ -226,7 +228,7 @@ class _CertificateUploadPageState extends State<CertificateUploadPage> {
const SizedBox(height: UiConstants.space2), const SizedBox(height: UiConstants.space2),
TextField( TextField(
controller: _numberController, controller: _numberController,
enabled: false, enabled: _isNewCertificate,
decoration: InputDecoration( decoration: InputDecoration(
hintText: 'Enter number if applicable', hintText: 'Enter number if applicable',
border: OutlineInputBorder( border: OutlineInputBorder(