Skip to content

Commit 6268b3b

Browse files
authored
Documentation Done for feature/share-application (#2992)
1 parent 3af50cd commit 6268b3b

File tree

8 files changed

+124
-34
lines changed

8 files changed

+124
-34
lines changed

feature/share-application/src/commonMain/kotlin/org/mifos/mobile/feature/share/application/di/ShareApplicationModule.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ import org.koin.dsl.module
1414
import org.mifos.mobile.feature.share.application.fillApplication.ShareFillApplicationViewModel
1515
import org.mifos.mobile.feature.share.application.shareApplication.ShareApplyViewModel
1616

17+
/**
18+
* Koin module for the Share Application feature.
19+
*
20+
* This module provides the ViewModels required for the share application screens.
21+
*/
1722
val shareApplicationModule = module {
1823
viewModelOf(::ShareApplyViewModel)
1924
viewModelOf(::ShareFillApplicationViewModel)

feature/share-application/src/commonMain/kotlin/org/mifos/mobile/feature/share/application/fillApplication/FillApplicationRoute.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,36 @@ import androidx.navigation.NavOptions
1717
import kotlinx.serialization.Serializable
1818
import org.mifos.mobile.core.ui.composableWithSlideTransitions
1919

20+
/**
21+
* A serializable data class representing the route to the Share Fill Application screen.
22+
*
23+
* @property shareProductId The ID of the share product to apply for.
24+
*/
2025
@Serializable
2126
data class ShareFillApplicationRoute(
2227
val shareProductId: Long,
2328
)
2429

30+
/**
31+
* Navigates to the Share Fill Application screen.
32+
*
33+
* @param shareProductId The ID of the share product.
34+
* @param navOptions Optional navigation options.
35+
*/
2536
fun NavController.navigateToShareFillApplicationScreen(
2637
shareProductId: Long,
2738
navOptions: NavOptions? = null,
2839
) {
2940
this.navigate(ShareFillApplicationRoute(shareProductId), navOptions)
3041
}
3142

43+
/**
44+
* Defines the destination for the Share Fill Application screen in the navigation graph.
45+
*
46+
* @param navigateToAuthenticateScreen A function to navigate to the authentication screen.
47+
* @param navigateToStatusScreen A function to navigate to the status screen.
48+
* @param navigateBack A function to navigate back to the previous screen.
49+
*/
3250
fun NavGraphBuilder.shareFillApplicationDestination(
3351
navigateToAuthenticateScreen: () -> Unit,
3452
navigateToStatusScreen: (String, String, String, String, String) -> Unit,

feature/share-application/src/commonMain/kotlin/org/mifos/mobile/feature/share/application/fillApplication/FillApplicationScreen.kt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ import org.mifos.mobile.core.ui.component.MifosProgressIndicator
6262
import org.mifos.mobile.core.ui.component.MifosProgressIndicatorOverlay
6363
import org.mifos.mobile.core.ui.utils.EventsEffect
6464

65+
/**
66+
* A Composable function that represents the Share Fill Application screen.
67+
*
68+
* @param navigateBack A function to navigate back to the previous screen.
69+
* @param navigateToStatusScreen A function to navigate to the status screen.
70+
* @param navigateToAuthenticateScreen A function to navigate to the authentication screen.
71+
* @param viewModel An instance of [ShareFillApplicationViewModel].
72+
*/
6573
@Composable
6674
internal fun ShareFillApplicationScreen(
6775
navigateBack: () -> Unit,
@@ -104,6 +112,12 @@ internal fun ShareFillApplicationScreen(
104112
)
105113
}
106114

115+
/**
116+
* A Composable function that displays a dialog based on the [ShareApplicationDialogState].
117+
*
118+
* @param dialogState The state of the dialog to be displayed.
119+
* @param onAction A function to handle actions from the dialog.
120+
*/
107121
@Composable
108122
internal fun ShareFillApplicationDialog(
109123
dialogState: ShareApplicationDialogState?,
@@ -130,6 +144,13 @@ internal fun ShareFillApplicationDialog(
130144
}
131145
}
132146

147+
/**
148+
* A Composable function that displays the content of the Share Fill Application screen.
149+
*
150+
* @param state The current state of the screen.
151+
* @param onAction A function to handle actions from the screen.
152+
* @param modifier A [Modifier] for the Composable.
153+
*/
133154
@Composable
134155
internal fun ShareFillApplicationContent(
135156
state: ShareApplicationState,
@@ -182,6 +203,13 @@ internal fun ShareFillApplicationContent(
182203
}
183204
}
184205

206+
/**
207+
* A Composable function that displays the form for the Share Fill Application screen.
208+
*
209+
* @param state The current state of the screen.
210+
* @param onAction A function to handle actions from the screen.
211+
* @param modifier A [Modifier] for the Composable.
212+
*/
185213
@Composable
186214
internal fun ShareFillApplicationForm(
187215
state: ShareApplicationState,

feature/share-application/src/commonMain/kotlin/org/mifos/mobile/feature/share/application/fillApplication/FillApplicationViewModel.kt

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ internal class ShareFillApplicationViewModel(
277277
accountsRepositoryImpl.loadAccounts(
278278
clientId = state.clientId,
279279
accountType = Constants.SAVINGS_ACCOUNTS,
280-
).catch {
280+
).catch { e ->
281281
mutableStateFlow.update {
282282
it.copy(
283283
uiState = ShareApplicationUiState.Error(Res.string.feature_apply_share_error_server),
@@ -315,7 +315,6 @@ internal class ShareFillApplicationViewModel(
315315
}
316316
is DataState.Success -> {
317317
val shareTemplate = response.data
318-
println(shareTemplate)
319318
updateState {
320319
it.copy(
321320
defaultAccounts = shareTemplate.savingsAccounts ?: emptyList(),
@@ -348,8 +347,6 @@ internal class ShareFillApplicationViewModel(
348347
}
349348
is DataState.Success -> {
350349
val shareTemplate = template.data ?: return
351-
println(shareTemplate)
352-
println(shareTemplate.accountingMappings?.toAccountList())
353350
updateState {
354351
it.copy(
355352
currency = shareTemplate.currency ?: Currency(),
@@ -380,10 +377,6 @@ internal class ShareFillApplicationViewModel(
380377
updateState { it.copy(uiState = ShareApplicationUiState.Loading) }
381378
}
382379

383-
/**
384-
* Sets the UI state to `OverlayLoading`.
385-
*/
386-
387380
/**
388381
* Sets the dialog state to an `Error` dialog.
389382
*
@@ -452,7 +445,7 @@ internal class ShareFillApplicationViewModel(
452445
*/
453446
private fun validateTotalShares(newValue: String): ValidationResult = when {
454447
newValue.isBlank() -> ValidationResult.Error(Res.string.feature_apply_share_error_shares_required)
455-
newValue.toIntOrNull() == null -> ValidationResult.Error(Res.string.feature_apply_share_shares_invalid)
448+
newValue.toLongOrNull() == null -> ValidationResult.Error(Res.string.feature_apply_share_shares_invalid)
456449
else -> ValidationResult.Success
457450
}
458451

@@ -783,6 +776,7 @@ internal class ShareFillApplicationViewModel(
783776
* @property networkStatus The current network connectivity status.
784777
* @property dialogState The state of the dialog to be displayed.
785778
* @property uiState The overall UI state (e.g., loading, success, error).
779+
* @property showOverlay A flag to show an overlay progress indicator.
786780
*/
787781
@OptIn(ExperimentalMaterial3Api::class)
788782
internal data class ShareApplicationState(

feature/share-application/src/commonMain/kotlin/org/mifos/mobile/feature/share/application/navigation/ShareApplicationNavGraph.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,28 @@ import org.mifos.mobile.feature.share.application.fillApplication.shareFillAppli
1919
import org.mifos.mobile.feature.share.application.shareApplication.ShareApplyRoute
2020
import org.mifos.mobile.feature.share.application.shareApplication.shareApplyDestination
2121

22+
/**
23+
* A serializable object representing the navigation graph for the Share Application feature.
24+
*/
2225
@Serializable
2326
data object ShareApplicationNavGraph
2427

28+
/**
29+
* Navigates to the Share Application navigation graph.
30+
*
31+
* @param navOptions Optional navigation options.
32+
*/
2533
fun NavController.navigateToShareApplicationGraph(navOptions: NavOptions? = null) {
2634
this.navigate(ShareApplicationNavGraph, navOptions)
2735
}
2836

37+
/**
38+
* Defines the navigation graph for the Share Application feature.
39+
*
40+
* @param navController The [NavController] for the graph.
41+
* @param navigateToAuthenticateScreen A function to navigate to the authentication screen.
42+
* @param navigateToStatusScreen A function to navigate to the status screen.
43+
*/
2944
fun NavGraphBuilder.shareApplicationNavGraph(
3045
navController: NavController,
3146
navigateToAuthenticateScreen: () -> Unit,

feature/share-application/src/commonMain/kotlin/org/mifos/mobile/feature/share/application/shareApplication/ShareApplyRoute.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,28 @@ import androidx.navigation.NavOptions
1515
import kotlinx.serialization.Serializable
1616
import org.mifos.mobile.core.ui.composableWithSlideTransitions
1717

18+
/**
19+
* A serializable object representing the route to the Share Apply screen.
20+
*/
1821
@Serializable
1922
data object ShareApplyRoute
2023

24+
/**
25+
* Navigates to the Share Apply screen.
26+
*
27+
* @param navOptions Optional navigation options.
28+
*/
2129
fun NavController.navigateToShareApplyScreen(
2230
navOptions: NavOptions? = null,
2331
) =
2432
navigate(ShareApplyRoute, navOptions)
2533

34+
/**
35+
* Defines the destination for the Share Apply screen in the navigation graph.
36+
*
37+
* @param navigateToFillDetailsScreen A function to navigate to the fill details screen.
38+
* @param navigateBack A function to navigate back to the previous screen.
39+
*/
2640
fun NavGraphBuilder.shareApplyDestination(
2741
navigateToFillDetailsScreen: (Long) -> Unit,
2842
navigateBack: () -> Unit,

feature/share-application/src/commonMain/kotlin/org/mifos/mobile/feature/share/application/shareApplication/ShareApplyScreen.kt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ import org.mifos.mobile.core.ui.component.MifosPoweredCard
5050
import org.mifos.mobile.core.ui.component.MifosProgressIndicator
5151
import org.mifos.mobile.core.ui.utils.EventsEffect
5252

53+
/**
54+
* A Composable function that represents the Share Apply screen.
55+
*
56+
* @param navigateBack A function to navigate back to the previous screen.
57+
* @param navigateToFillDetailsScreen A function to navigate to the fill details screen.
58+
* @param viewModel An instance of [ShareApplyViewModel].
59+
*/
5360
@Composable
5461
internal fun ShareApplyScreen(
5562
navigateBack: () -> Unit,
@@ -85,6 +92,12 @@ internal fun ShareApplyScreen(
8592
)
8693
}
8794

95+
/**
96+
* A Composable function that displays a dialog based on the [ShareApplicationDialogState].
97+
*
98+
* @param dialogState The state of the dialog to be displayed.
99+
* @param onAction A function to handle actions from the dialog.
100+
*/
88101
@Composable
89102
internal fun ShareApplicationDialog(
90103
dialogState: ShareApplicationDialogState?,
@@ -105,6 +118,13 @@ internal fun ShareApplicationDialog(
105118
}
106119
}
107120

121+
/**
122+
* A Composable function that displays the content of the Share Application screen.
123+
*
124+
* @param state The current state of the screen.
125+
* @param onAction A function to handle actions from the screen.
126+
* @param modifier A [Modifier] for the Composable.
127+
*/
108128
@Composable
109129
internal fun ShareApplicationContent(
110130
state: ShareApplicationState,
@@ -163,6 +183,13 @@ internal fun ShareApplicationContent(
163183
}
164184
}
165185

186+
/**
187+
* A Composable function that displays the form for the Share Application screen.
188+
*
189+
* @param state The current state of the screen.
190+
* @param onAction A function to handle actions from the screen.
191+
* @param modifier A [Modifier] for the Composable.
192+
*/
166193
@Composable
167194
internal fun ShareApplicationForm(
168195
state: ShareApplicationState,

feature/share-application/src/commonMain/kotlin/org/mifos/mobile/feature/share/application/shareApplication/ShareApplyViewModel.kt

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,6 @@ internal class ShareApplyViewModel(
6767
observeNetworkStatus()
6868
}
6969

70-
/*
71-
* Functions related to Data Observation and Fetching
72-
*/
73-
7470
/**
7571
* Observes the network connectivity status and updates the UI state accordingly.
7672
* If the network is unavailable, it sets the `networkUnavailable` flag in the state
@@ -98,7 +94,7 @@ internal class ShareApplyViewModel(
9894
* When the app is **online**:
9995
* - It immediately updates the `networkStatus` in the state to `true`.
10096
* - It then triggers essential functions to **refresh data** and ensure the UI is up-to-date,
101-
* specifically by calling `unreadNotificationsCount()` and `loadClientAccountDetails()`.
97+
* specifically by calling `getClientDataAndTemplate()`.
10298
*
10399
* @param isOnline A `Boolean` indicating the current network connectivity status.
104100
*
@@ -125,8 +121,7 @@ internal class ShareApplyViewModel(
125121
}
126122

127123
/**
128-
* Fetches client data, a generic share template, and a product-specific loan purpose template
129-
* from the repositories.
124+
* Fetches client data and a generic share template from the repositories.
130125
* The results are combined and handled in a single flow to manage loading and error states.
131126
*/
132127
private fun getClientDataAndTemplate() {
@@ -166,6 +161,7 @@ internal class ShareApplyViewModel(
166161
* Updates the state with product options and currency on success,
167162
* or displays an error and navigates back on failure.
168163
*
164+
* @param client The [DataState] containing the client data.
169165
* @param template The [DataState] containing the savings template data.
170166
*/
171167
private fun handleClientAndSavingsTemplate(
@@ -202,7 +198,7 @@ internal class ShareApplyViewModel(
202198

203199
/**
204200
* Retries the data fetching process. If the network is unavailable, it shows
205-
* a network error dialog. Otherwise, it triggers the `fetchShareTemplate` `fetchClient`,
201+
* a network error dialog. Otherwise, it triggers the `getClientDataAndTemplate` function.
206202
*/
207203
private fun retry() {
208204
viewModelScope.launch {
@@ -214,10 +210,6 @@ internal class ShareApplyViewModel(
214210
}
215211
}
216212

217-
/*
218-
* Functions related to UI State and Dialogs
219-
*/
220-
221213
/**
222214
* A helper function to update the mutable state flow.
223215
*
@@ -252,10 +244,6 @@ internal class ShareApplyViewModel(
252244
}
253245
}
254246

255-
/*
256-
* Functions related to User Input and Validation
257-
*/
258-
259247
/**
260248
* Handles incoming actions from the UI and dispatches them to the appropriate
261249
* business logic functions.
@@ -287,8 +275,7 @@ internal class ShareApplyViewModel(
287275

288276
/**
289277
* Handles changes to the selected savings product.
290-
* It updates the state, fetches the corresponding field officer options,
291-
* and debounces validation.
278+
* It updates the state with the new product ID and name.
292279
*
293280
* @param id The ID of the selected savings product.
294281
* @param name The name of the selected savings product.
@@ -331,10 +318,6 @@ internal class ShareApplyViewModel(
331318
}
332319
}
333320

334-
/*
335-
* Functions related to Navigation and Lifecycle
336-
*/
337-
338321
/**
339322
* Handles the back navigation. If there are unsaved changes, it shows a
340323
* confirmation dialog. Otherwise, it sends an event to navigate back.
@@ -360,11 +343,13 @@ internal class ShareApplyViewModel(
360343
* @property clientId The ID of the current client.
361344
* @property applicantName The name of the applicant.
362345
* @property productOptions A list of available savings product options.
346+
* @property selectedShareProduct The name of the selected share product.
347+
* @property selectedShareProductId The ID of the selected share product.
348+
* @property dialogState The state of any dialogs that overlay the main content.
363349
* @property savingsProductTemplate The full savings template object for the selected product.
364350
* @property hasChanges A boolean indicating if there are unsaved changes.
365351
* @property networkStatus A boolean indicating if the network is unavailable.
366352
* @property uiState The primary UI state of the screen (e.g., Loading, Empty, Success).
367-
* @property dialogState The state of any dialogs that overlay the main content.
368353
*/
369354
@OptIn(ExperimentalMaterial3Api::class)
370355
internal data class ShareApplicationState(
@@ -399,6 +384,9 @@ internal data class ShareApplicationState(
399384
}
400385
.toMap()
401386

387+
/**
388+
* The current date formatted as a string.
389+
*/
402390
@OptIn(ExperimentalTime::class)
403391
val submittedOnDate: String
404392
get() {
@@ -496,8 +484,9 @@ internal sealed interface ShareApplicationAction {
496484
data class ReceiveNetworkResult(val isOnline: Boolean) : ShareApplicationAction
497485

498486
/**
499-
* An internal action to handle the result of fetching a savings template.
500-
* @property template The [DataState] containing the savings template data.
487+
* An internal action to handle the result of fetching client and template data.
488+
* @property client The [DataState] containing the client data.
489+
* @property template The [DataState] containing the share product data.
501490
*/
502491
data class ReceiveClientAndTemplateResult(
503492
val client: DataState<Client>,

0 commit comments

Comments
 (0)