-
Notifications
You must be signed in to change notification settings - Fork 698
feat(loan): implement create guarantor screen #2698
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
80 changes: 80 additions & 0 deletions
80
core/data/src/commonMain/kotlin/com/mifos/core/data/mappers/loan/GuarantorMapper.kt
This file contains hidden or 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,80 @@ | ||
| /* | ||
| * Copyright 2026 Mifos Initiative | ||
| * | ||
| * This Source Code Form is subject to the terms of the Mozilla Public | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
| * | ||
| * See https://github.com/openMF/mifos-x-field-officer-app/blob/master/LICENSE.md | ||
| */ | ||
| package com.mifos.core.data.mappers.loan | ||
|
|
||
| import com.mifos.core.model.objects.account.loan.guarantor.CreateGuarantor | ||
| import com.mifos.core.model.objects.account.loan.guarantor.CreateGuarantorInput | ||
| import com.mifos.core.model.objects.account.loan.guarantor.GuarantorAccountTemplate | ||
| import com.mifos.core.model.objects.account.loan.guarantor.GuarantorRelationshipOption | ||
| import com.mifos.core.model.objects.account.loan.guarantor.GuarantorTemplate | ||
| import com.mifos.core.model.objects.account.loan.guarantor.GuarantorType | ||
| import com.mifos.core.network.dto.loans.CreateGuarantorResponseDto | ||
| import com.mifos.core.network.dto.loans.GuarantorAccountTemplateDto | ||
| import com.mifos.core.network.dto.loans.GuarantorRelationshipOptionDto | ||
| import com.mifos.core.network.dto.loans.GuarantorRequestDto | ||
| import com.mifos.core.network.dto.loans.GuarantorTemplateDto | ||
| import com.mifos.core.network.dto.loans.GuarantorTypeDto | ||
|
|
||
| fun GuarantorTemplateDto.toDomain(): GuarantorTemplate = | ||
| GuarantorTemplate( | ||
| allowedClientRelationshipTypes = allowedClientRelationshipTypes.map { it.toDomain() }, | ||
| guarantorTypeOptions = guarantorTypeOptions.map { it.toDomain() }, | ||
| ) | ||
|
|
||
| fun GuarantorRelationshipOptionDto.toDomain(): GuarantorRelationshipOption = | ||
| GuarantorRelationshipOption( | ||
| id = id, | ||
| name = name, | ||
| ) | ||
|
|
||
| fun CreateGuarantorResponseDto.toDomain(): CreateGuarantor = | ||
| CreateGuarantor( | ||
| resourceId = resourceId, | ||
| loanId = loanId, | ||
| officeId = officeId, | ||
| ) | ||
|
|
||
| fun CreateGuarantorInput.toDto(): GuarantorRequestDto { | ||
| return GuarantorRequestDto( | ||
| clientRelationshipTypeId = clientRelationshipTypeId, | ||
| dateFormat = dateFormat, | ||
| entityId = entityId, | ||
| guarantorTypeId = guarantorTypeId, | ||
| locale = locale, | ||
| firstname = firstname, | ||
| lastname = lastname, | ||
| dob = dob, | ||
| addressLine1 = addressLine1, | ||
| addressLine2 = addressLine2, | ||
| city = city, | ||
| zip = zip, | ||
| mobileNumber = mobileNumber, | ||
| housePhoneNumber = housePhoneNumber, | ||
| ) | ||
| } | ||
|
|
||
| fun GuarantorAccountTemplateDto.toDomain(): GuarantorAccountTemplate { | ||
| return GuarantorAccountTemplate( | ||
| guarantorType = guarantorType.toDomain(), | ||
| status = status, | ||
| externalGuarantor = externalGuarantor, | ||
| existingGroup = existingGroup, | ||
| existingClient = existingClient, | ||
| staffMember = staffMember, | ||
| ) | ||
| } | ||
|
|
||
| fun GuarantorTypeDto.toDomain(): GuarantorType { | ||
| return GuarantorType( | ||
| id = id, | ||
| code = code, | ||
| value = value, | ||
| ) | ||
| } |
31 changes: 31 additions & 0 deletions
31
...ata/src/commonMain/kotlin/com/mifos/core/data/repository/LoanCreateGuarantorRepository.kt
This file contains hidden or 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,31 @@ | ||
| /* | ||
| * Copyright 2026 Mifos Initiative | ||
| * | ||
| * This Source Code Form is subject to the terms of the Mozilla Public | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
| * | ||
| * See https://github.com/openMF/mifos-x-field-officer-app/blob/master/LICENSE.md | ||
| */ | ||
| package com.mifos.core.data.repository | ||
|
|
||
| import com.mifos.core.common.utils.DataState | ||
| import com.mifos.core.model.objects.account.loan.guarantor.CreateGuarantor | ||
| import com.mifos.core.model.objects.account.loan.guarantor.CreateGuarantorInput | ||
| import com.mifos.core.model.objects.account.loan.guarantor.GuarantorAccountTemplate | ||
| import com.mifos.core.model.objects.account.loan.guarantor.GuarantorTemplate | ||
|
|
||
| interface LoanCreateGuarantorRepository { | ||
|
|
||
| suspend fun getGuarantorTemplate(loanId: Int): DataState<GuarantorTemplate> | ||
|
|
||
| suspend fun createGuarantor( | ||
| loanId: Int, | ||
| createGuarantorInput: CreateGuarantorInput, | ||
| ): DataState<CreateGuarantor> | ||
|
|
||
| suspend fun getGuarantorAccountTemplate( | ||
| loanId: Int, | ||
| clientId: Int, | ||
| ): DataState<GuarantorAccountTemplate> | ||
| } |
68 changes: 68 additions & 0 deletions
68
...c/commonMain/kotlin/com/mifos/core/data/repositoryImp/LoanCreateGuarantorRepositoryImp.kt
This file contains hidden or 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,68 @@ | ||
| /* | ||
| * Copyright 2026 Mifos Initiative | ||
| * | ||
| * This Source Code Form is subject to the terms of the Mozilla Public | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
| * | ||
| * See https://github.com/openMF/mifos-x-field-officer-app/blob/master/LICENSE.md | ||
| */ | ||
| package com.mifos.core.data.repositoryImp | ||
|
|
||
| import com.mifos.core.common.utils.DataState | ||
| import com.mifos.core.data.mappers.loan.toDomain | ||
| import com.mifos.core.data.mappers.loan.toDto | ||
| import com.mifos.core.data.repository.LoanCreateGuarantorRepository | ||
| import com.mifos.core.data.util.NetworkMonitor | ||
| import com.mifos.core.data.util.runAsDataState | ||
| import com.mifos.core.model.objects.account.loan.guarantor.CreateGuarantor | ||
| import com.mifos.core.model.objects.account.loan.guarantor.CreateGuarantorInput | ||
| import com.mifos.core.model.objects.account.loan.guarantor.GuarantorAccountTemplate | ||
| import com.mifos.core.model.objects.account.loan.guarantor.GuarantorTemplate | ||
| import com.mifos.core.network.datamanager.DataManagerLoan | ||
| import kotlinx.coroutines.CoroutineDispatcher | ||
|
|
||
| class LoanCreateGuarantorRepositoryImp( | ||
| private val dataManagerLoan: DataManagerLoan, | ||
| private val ioDispatcher: CoroutineDispatcher, | ||
| private val networkMonitor: NetworkMonitor, | ||
| ) : LoanCreateGuarantorRepository { | ||
|
|
||
| override suspend fun getGuarantorTemplate(loanId: Int): DataState<GuarantorTemplate> { | ||
| return runAsDataState( | ||
| networkMonitor, | ||
| ioDispatcher, | ||
| ) { | ||
| dataManagerLoan.getGuarantorTemplate(loanId).toDomain() | ||
| } | ||
| } | ||
|
|
||
| override suspend fun createGuarantor( | ||
| loanId: Int, | ||
| createGuarantorInput: CreateGuarantorInput, | ||
| ): DataState<CreateGuarantor> { | ||
| return runAsDataState( | ||
| networkMonitor, | ||
| ioDispatcher, | ||
| ) { | ||
| dataManagerLoan.createGuarantor(loanId, createGuarantorInput.toDto()).toDomain() | ||
| } | ||
| } | ||
|
|
||
| override suspend fun getGuarantorAccountTemplate( | ||
| loanId: Int, | ||
| clientId: Int, | ||
| ): DataState<GuarantorAccountTemplate> { | ||
| return runAsDataState( | ||
| networkMonitor, | ||
| ioDispatcher, | ||
| ) { | ||
| dataManagerLoan | ||
| .getGuarantorAccountTemplate( | ||
| loanId = loanId, | ||
| clientId = clientId, | ||
| ) | ||
| .toDomain() | ||
| } | ||
| } | ||
| } |
119 changes: 119 additions & 0 deletions
119
...em/src/commonMain/kotlin/com/mifos/core/designsystem/component/MifosSearchableDropdown.kt
This file contains hidden or 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,119 @@ | ||
| /* | ||
| * Copyright 2026 Mifos Initiative | ||
| * | ||
| * This Source Code Form is subject to the terms of the Mozilla Public | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
| * | ||
| * See https://github.com/openMF/mifos-x-field-officer-app/blob/master/LICENSE.md | ||
| */ | ||
| package com.mifos.core.designsystem.component | ||
|
|
||
| import androidx.compose.foundation.layout.fillMaxWidth | ||
| import androidx.compose.foundation.text.KeyboardOptions | ||
| import androidx.compose.material3.DropdownMenuItem | ||
| import androidx.compose.material3.ExperimentalMaterial3Api | ||
| import androidx.compose.material3.ExposedDropdownMenuAnchorType | ||
| import androidx.compose.material3.ExposedDropdownMenuBox | ||
| import androidx.compose.material3.ExposedDropdownMenuDefaults | ||
| import androidx.compose.material3.OutlinedTextField | ||
| import androidx.compose.material3.OutlinedTextFieldDefaults | ||
| import androidx.compose.material3.Text | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.runtime.getValue | ||
| import androidx.compose.runtime.mutableStateOf | ||
| import androidx.compose.runtime.remember | ||
| import androidx.compose.runtime.setValue | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.draw.clip | ||
| import androidx.compose.ui.text.input.ImeAction | ||
| import com.mifos.core.designsystem.theme.DesignToken | ||
| import com.mifos.core.designsystem.theme.MifosTypography | ||
| import template.core.base.designsystem.theme.KptTheme | ||
|
|
||
| @OptIn(ExperimentalMaterial3Api::class) | ||
| @Composable | ||
| fun MifosSearchableDropdown( | ||
| value: String, | ||
| onValueChanged: (String) -> Unit, | ||
| onOptionSelected: (Int, String) -> Unit, | ||
| options: List<String>, | ||
| modifier: Modifier = Modifier | ||
| .clip(DesignToken.shapes.medium) | ||
| .fillMaxWidth(), | ||
| label: String? = null, | ||
| enabled: Boolean = true, | ||
| errorMessage: String? = null, | ||
| ) { | ||
| var expanded by remember { mutableStateOf(false) } | ||
|
|
||
| ExposedDropdownMenuBox( | ||
| expanded = expanded && enabled && options.isNotEmpty(), | ||
| onExpandedChange = { | ||
| if (enabled) { | ||
| expanded = !expanded | ||
| } | ||
| }, | ||
| ) { | ||
| OutlinedTextField( | ||
| value = value, | ||
| onValueChange = { | ||
| onValueChanged(it) | ||
| expanded = true | ||
| }, | ||
| enabled = enabled, | ||
| readOnly = false, | ||
| isError = errorMessage != null, | ||
| supportingText = { | ||
| errorMessage?.let { | ||
| Text( | ||
| text = it, | ||
| color = KptTheme.colorScheme.error, | ||
| ) | ||
| } | ||
| }, | ||
| label = { | ||
| label?.let { | ||
| Text(text = it) | ||
| } | ||
| }, | ||
| modifier = modifier.menuAnchor( | ||
| type = ExposedDropdownMenuAnchorType.PrimaryEditable, | ||
| enabled = enabled, | ||
| ), | ||
| shape = DesignToken.shapes.medium, | ||
| colors = OutlinedTextFieldDefaults.colors( | ||
| focusedBorderColor = KptTheme.colorScheme.secondaryContainer, | ||
| unfocusedBorderColor = KptTheme.colorScheme.secondaryContainer, | ||
| ), | ||
| maxLines = 1, | ||
| textStyle = MifosTypography.bodyLarge, | ||
| keyboardOptions = KeyboardOptions.Default.copy( | ||
| imeAction = ImeAction.Done, | ||
| ), | ||
| trailingIcon = { | ||
| ExposedDropdownMenuDefaults.TrailingIcon(expanded = expanded) | ||
| }, | ||
| ) | ||
|
|
||
| ExposedDropdownMenu( | ||
| expanded = expanded && options.isNotEmpty(), | ||
| onDismissRequest = { | ||
| expanded = false | ||
| }, | ||
| ) { | ||
| options.forEachIndexed { index, item -> | ||
| DropdownMenuItem( | ||
| text = { | ||
| Text(text = item) | ||
| }, | ||
| onClick = { | ||
| expanded = false | ||
| onValueChanged(item) | ||
| onOptionSelected(index, item) | ||
| }, | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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
24 changes: 24 additions & 0 deletions
24
...ommonMain/kotlin/com/mifos/core/domain/useCases/createGuarantor/CreateGuarantorUseCase.kt
This file contains hidden or 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,24 @@ | ||
| /* | ||
| * Copyright 2026 Mifos Initiative | ||
| * | ||
| * This Source Code Form is subject to the terms of the Mozilla Public | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
| * | ||
| * See https://github.com/openMF/mifos-x-field-officer-app/blob/master/LICENSE.md | ||
| */ | ||
| package com.mifos.core.domain.useCases.createGuarantor | ||
|
|
||
| import com.mifos.core.common.utils.DataState | ||
| import com.mifos.core.data.repository.LoanCreateGuarantorRepository | ||
| import com.mifos.core.model.objects.account.loan.guarantor.CreateGuarantor | ||
| import com.mifos.core.model.objects.account.loan.guarantor.CreateGuarantorInput | ||
|
|
||
| class CreateGuarantorUseCase( | ||
| private val repository: LoanCreateGuarantorRepository, | ||
| ) { | ||
| suspend operator fun invoke( | ||
| loanId: Int, | ||
| createGuarantorInput: CreateGuarantorInput, | ||
| ): DataState<CreateGuarantor> = repository.createGuarantor(loanId, createGuarantorInput) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.