Skip to content
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions feature/collectionSheet/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ plugins {
alias(libs.plugins.kotlin.serialization)
}


android {
namespace = "com.mifos.feature.collection_sheet"
}
Expand All @@ -25,11 +26,16 @@ kotlin {
implementation(compose.ui)
implementation(projects.core.domain)
implementation(libs.kotlinx.serialization.json)
implementation(compose.components.uiToolingPreview)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this as u already defined in dependencies {} block

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i mentioned remove it from commonMain but keep the dependencies{}:

  • cause when we create a project from KMP wizard this way it is done by default maybe they have sth in mind where in future the previews will work for all platform if we have it here
dependencies {
    debugImplementation(compose.uiTooling)
}


implementation(libs.coil.core)
implementation(libs.coil.kt)
implementation(libs.coil.kt.compose)

}
}
}

dependencies {
debugImplementation(compose.uiTooling)
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,4 @@
<string name="feature_collection_sheet_productive_collection_sheet">Productive Collection Sheet</string>
<string name="feature_collection_sheet_productive_sheet_submitted">Productive Sheet Submitted Successfully</string>
<string name="feature_collection_sheet_collection_sheet_submitted">Collection Sheet Submitted Successfully</string>

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ import androidx.compose.ui.Modifier
import com.mifos.core.designsystem.component.MifosScaffold
import com.mifos.core.designsystem.component.MifosTabRow
import com.mifos.core.designsystem.utility.TabContent
import com.mifos.core.ui.util.DevicePreview
import com.mifos.feature.individualCollectionSheet.newIndividualCollectionSheet.NewIndividualCollectionSheetScreen
import com.mifos.feature.individualCollectionSheet.savedIndividualCollectionSheet.SavedIndividualCollectionSheetCompose
import com.mifos.room.entities.collectionsheet.IndividualCollectionSheet
import org.jetbrains.compose.resources.stringResource
import org.jetbrains.compose.ui.tooling.preview.Preview

@Composable
internal fun IndividualCollectionSheetScreen(
Expand Down Expand Up @@ -69,7 +69,7 @@ enum class IndividualCollectionSheetScreenContents {
SAVED,
}

@DevicePreview
@Preview
@Composable
private fun IndividualCollectionSheetScreenPreview() {
IndividualCollectionSheetScreen(onBackPressed = {}, onDetail = { _, _ -> })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ import com.mifos.core.designsystem.icon.MifosIcons
import com.mifos.core.model.objects.account.loan.PaymentTypeOptions
import com.mifos.core.model.objects.collectionsheets.LoanAndClientName
import com.mifos.core.network.model.IndividualCollectionSheetPayload
import com.mifos.core.ui.util.DevicePreview
import com.mifos.room.entities.collectionsheet.ClientCollectionSheet
import com.mifos.room.entities.collectionsheet.IndividualCollectionSheet
import com.mifos.room.entities.noncore.BulkRepaymentTransactions
import kotlinx.coroutines.launch
import org.jetbrains.compose.resources.painterResource
import org.jetbrains.compose.resources.stringResource
import org.jetbrains.compose.ui.tooling.preview.Preview
import org.koin.compose.viewmodel.koinViewModel

@Composable
Expand Down Expand Up @@ -210,6 +210,8 @@ private fun IndividualCollectionSheetItem(
modifier: Modifier = Modifier,
onClick: () -> Unit,
) {
val loan = client.loans?.getOrNull(index)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i see that this index is not use anywhere except finding the loan. so instead of passing index why not passing the loan itself from place this composable is called


OutlinedCard(
modifier = modifier
.padding(6.dp)
Expand Down Expand Up @@ -246,18 +248,16 @@ private fun IndividualCollectionSheetItem(
Text(
text = it,
style = MaterialTheme.typography.bodyLarge,

)
}
Row {
Text(
text = stringResource(Res.string.feature_collection_sheet_total_due),
style = MaterialTheme.typography.bodyMedium,

)
Spacer(modifier = Modifier.width(16.dp))
Text(
text = client.loans?.get(index)?.totalDue.toString(),
text = (loan?.totalDue ?: 0).toString(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • the zero should be in this format 0.0
  • i see this screen there are things that need to be taken care of at viewmodel and the screen should only display to user, but no worries for now we should come back for all of these

style = MaterialTheme.typography.bodyMedium,
)
}
Expand All @@ -268,18 +268,16 @@ private fun IndividualCollectionSheetItem(
)
Spacer(modifier = Modifier.width(16.dp))
Text(
text = client.loans?.get(index)?.chargesDue.toString(),
text = (loan?.chargesDue ?: 0).toString(),
style = MaterialTheme.typography.bodyMedium,
)
}
if (loan?.productShortName != null) {
Text(
text = "${loan.productShortName} (#${loan.productShortName})",
style = MaterialTheme.typography.bodyMedium,
)
}
Text(
text = "${client.loans?.get(index)?.productShortName} (#${
client.loans?.get(
index,
)?.productShortName
})",
style = MaterialTheme.typography.bodyMedium,
)
}
Icon(
imageVector = MifosIcons.ArrowForward,
Expand All @@ -289,7 +287,7 @@ private fun IndividualCollectionSheetItem(
}
}

@DevicePreview
@Preview
@Composable
private fun IndividualCollectionSheetDetailsScreenEmptyPreview() {
IndividualCollectionSheetDetailsScreen(
Expand All @@ -303,7 +301,7 @@ private fun IndividualCollectionSheetDetailsScreenEmptyPreview() {
)
}

@DevicePreview
@Preview
@Composable
private fun IndividualCollectionSheetDetailsScreenErrorPreview() {
IndividualCollectionSheetDetailsScreen(
Expand All @@ -317,7 +315,7 @@ private fun IndividualCollectionSheetDetailsScreenErrorPreview() {
)
}

@DevicePreview
@Preview
@Composable
private fun IndividualCollectionSheetDetailsScreenLoadingPreview() {
IndividualCollectionSheetDetailsScreen(
Expand All @@ -331,7 +329,7 @@ private fun IndividualCollectionSheetDetailsScreenLoadingPreview() {
)
}

@DevicePreview
@Preview
@Composable
private fun IndividualCollectionSheetDetailsScreenSuccessPreview() {
IndividualCollectionSheetDetailsScreen(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import com.mifos.feature.individualCollectionSheet.individualCollectionSheetDeta
import com.mifos.feature.individualCollectionSheet.paymentDetails.PaymentDetailsScreenRoute
import com.mifos.room.entities.collectionsheet.IndividualCollectionSheet
import kotlinx.serialization.Serializable
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json

fun NavGraphBuilder.individualCollectionSheetNavGraph(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ import com.mifos.core.designsystem.component.MifosDatePickerTextField
import com.mifos.core.designsystem.component.MifosScaffold
import com.mifos.core.designsystem.component.MifosTextFieldDropdown
import com.mifos.core.network.model.RequestCollectionSheetPayload
import com.mifos.core.ui.util.DevicePreview
import com.mifos.room.entities.collectionsheet.IndividualCollectionSheet
import com.mifos.room.entities.organisation.OfficeEntity
import com.mifos.room.entities.organisation.StaffEntity
import kotlinx.datetime.Clock
import org.jetbrains.compose.resources.stringResource
import org.jetbrains.compose.ui.tooling.preview.Preview
import org.koin.compose.viewmodel.koinViewModel

@Composable
Expand Down Expand Up @@ -120,7 +120,11 @@ internal fun NewIndividualCollectionSheetScreen(
var showCollectionSheetDialog by rememberSaveable { mutableStateOf(false) }

var showDatePicker by rememberSaveable { mutableStateOf(false) }
var repaymentDate by rememberSaveable { mutableLongStateOf(Clock.System.now().toEpochMilliseconds()) }
var repaymentDate by rememberSaveable {
mutableLongStateOf(
Clock.System.now().toEpochMilliseconds(),
)
}
val datePickerState = rememberDatePickerState(
initialSelectedDateMillis = repaymentDate,
selectableDates = object : SelectableDates {
Expand Down Expand Up @@ -229,12 +233,24 @@ internal fun NewIndividualCollectionSheetScreen(
selectedStaff = ""
},
onOptionSelected = { index, value ->
state.officeList[index].id.let {
getStaffList(it)
officeId = it
println("DEBUG: Office selection - Index: $index, List size: ${state.officeList.size}, Value: $value")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove all of these println

try {
if (index >= 0 && index < state.officeList.size) {
val selectedOfficeEntity = state.officeList[index]
selectedOfficeEntity.id?.let {
getStaffList(it)
officeId = it
}
selectedOffice = value
selectedStaff = ""
println("DEBUG: Office selection successful")
} else {
println("DEBUG: Office index out of bounds: $index for size ${state.officeList.size}")
}
} catch (e: Exception) {
println("DEBUG: Error in office selection: ${e.message}")
println("DEBUG: Full error: ${e.stackTraceToString()}")
}
selectedOffice = value
selectedStaff = ""
},
label = stringResource(Res.string.feature_collection_sheet_office),
options = state.officeList.map { it.name.toString() },
Expand All @@ -254,10 +270,21 @@ internal fun NewIndividualCollectionSheetScreen(
selectedStaff = it
},
onOptionSelected = { index, value ->
state.staffList[index].id?.let {
staffId = it
try {
if (index >= 0 && index < state.staffList.size) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

having these codes like try/cathc is highly discouraged in UI. use build it extension functions: sth like below change accordingly

state.officeList.getOrNull(index)?.let { selectedOfficeEntity ->
    selectedOfficeEntity.id?.let {
        getStaffList(it)
        officeId = it
    }
    selectedOffice = selectedOfficeEntity.name.toString()
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@HekmatullahAmin as you requested I have done changes can you do review now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After that I will run the spotlessApply

val selectedStaffEntity = state.staffList[index]
selectedStaffEntity.id?.let {
staffId = it
}
selectedStaff = value
println("DEBUG: Staff selection successful")
} else {
println("DEBUG: Staff index out of bounds: $index for size ${state.staffList.size}")
}
} catch (e: Exception) {
println("DEBUG: Error in staff selection: ${e.message}")
println("DEBUG: Full error: ${e.stackTraceToString()}")
}
selectedStaff = value
},
label = stringResource(Res.string.feature_collection_sheet_staff),
options = state.staffList.map { it.displayName.toString() },
Expand Down Expand Up @@ -388,7 +415,7 @@ private fun CollectionSheetDialogContent(
)
}

@DevicePreview
@Preview
@Composable
private fun NewIndividualCollectionSheetPreview() {
Column {
Expand Down Expand Up @@ -438,7 +465,7 @@ val sampleOfficeList = List(10) {
OfficeEntity(id = it, name = "Name")
}

@DevicePreview
@Preview
@Composable
private fun CollectionSheetDialogContentPreview() {
CollectionSheetDialogContent(date = "19 June 2024", member = "5", fillNow = {}, onDismiss = {})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.sp
import com.mifos.core.ui.util.DevicePreview
import org.jetbrains.compose.resources.stringResource
import org.jetbrains.compose.ui.tooling.preview.Preview

@Composable
internal fun SavedIndividualCollectionSheetCompose(
Expand Down Expand Up @@ -55,7 +55,7 @@ internal fun SavedIndividualCollectionSheetCompose(
}
}

@DevicePreview
@Preview
@Composable
private fun SavedIndividualCollectionSheetComposePreview() {
SavedIndividualCollectionSheetCompose()
Expand Down