Skip to content
Open
Show file tree
Hide file tree
Changes from 10 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
2 changes: 2 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,6 +26,7 @@ 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)
Expand Down
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 @@ -30,6 +30,7 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.Icon
Expand Down Expand Up @@ -58,14 +59,15 @@ import com.mifos.core.designsystem.component.MifosSweetError
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.model.objects.collectionsheets.LoanCollectionSheet
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 @@ -178,17 +180,17 @@ internal fun IndividualCollectionSheetDetailsScreen(
} else {
LazyColumn {
Copy link
Member

Choose a reason for hiding this comment

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

whenever u use LazyColumn use key for better performance

sheet.clients?.toList()?.let {
itemsIndexed(it) { index, client ->
items(it.zip(loansAndClientNames)) { (client, loanAndClientName) ->
IndividualCollectionSheetItem(
client = client,
index = index,
loan = loanAndClientName.loan,
onClick = {
sheet.paymentTypeOptions?.let { paymentTypeOptions ->
submit(
index,
0,
Copy link
Member

Choose a reason for hiding this comment

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

  • By removing index i meant to remove it from composable and just pass the loan as a parameter instead of going to composable and finding again using the index. where the index is not used in that composable at any line.
  • but you removed the index from submit and other areas an hardcoded it.
  • when i review the code i compare it to the previous code cause i am not fully aware of each variable and what specefic screen do. so keep the things as before just inside the IndividualCollectionSheetItem instead of passing index pass the loan using maybe client.loans?.get(index).
  • so have itemsIndexed as before

payload,
paymentTypeOptions.map { paymentTypeOption -> paymentTypeOption.name.toString() },
loansAndClientNames[index],
paymentTypeOptions.map { it.name.toString() },
loanAndClientName,
paymentTypeOptions.toList(),
client.clientId,
)
Expand All @@ -206,10 +208,11 @@ internal fun IndividualCollectionSheetDetailsScreen(
@Composable
private fun IndividualCollectionSheetItem(
client: ClientCollectionSheet,
index: Int,
loan: LoanCollectionSheet?,
modifier: Modifier = Modifier,
onClick: () -> Unit,
) {

OutlinedCard(
modifier = modifier
.padding(6.dp)
Expand Down Expand Up @@ -246,18 +249,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.0).toString(),
style = MaterialTheme.typography.bodyMedium,
)
}
Expand All @@ -268,18 +269,16 @@ private fun IndividualCollectionSheetItem(
)
Spacer(modifier = Modifier.width(16.dp))
Text(
text = client.loans?.get(index)?.chargesDue.toString(),
text = (loan?.chargesDue ?: 0.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 +288,7 @@ private fun IndividualCollectionSheetItem(
}
}

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

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

@DevicePreview
@Preview
@Composable
private fun IndividualCollectionSheetDetailsScreenLoadingPreview() {
IndividualCollectionSheetDetailsScreen(
Expand All @@ -331,7 +330,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,15 @@ internal fun NewIndividualCollectionSheetScreen(
selectedStaff = ""
},
onOptionSelected = { index, value ->
state.officeList[index].id.let {
getStaffList(it)
officeId = it
state.officeList.getOrNull(index)?.let { selectedOfficeEntity ->
selectedOfficeEntity.id.let {
getStaffList(it)
officeId = it
}
selectedOffice = selectedOfficeEntity.name.toString()
selectedStaff = ""
}
selectedOffice = value
selectedStaff = ""

},
label = stringResource(Res.string.feature_collection_sheet_office),
options = state.officeList.map { it.name.toString() },
Expand All @@ -254,7 +261,8 @@ internal fun NewIndividualCollectionSheetScreen(
selectedStaff = it
},
onOptionSelected = { index, value ->
state.staffList[index].id?.let {
val selectedStaffEntity = state.staffList[index]
selectedStaffEntity.id?.let {
staffId = it
}
selectedStaff = value
Expand Down Expand Up @@ -388,7 +396,7 @@ private fun CollectionSheetDialogContent(
)
}

@DevicePreview
@Preview
@Composable
private fun NewIndividualCollectionSheetPreview() {
Column {
Expand Down Expand Up @@ -438,7 +446,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
Loading