Skip to content

Commit

Permalink
[FEATURE] #85 : 매니저인 경우, survey-check로 전환하는 버튼 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
jeongjaino committed Jan 13, 2024
1 parent 942757e commit 06ff210
Showing 1 changed file with 14 additions and 84 deletions.
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
package com.wap.wapp.feature.survey

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SnackbarHost
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
Expand All @@ -26,13 +14,11 @@ import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.wap.designsystem.WappTheme
import com.wap.designsystem.component.WappMainTopBar
import com.wap.wapp.core.commmon.extensions.toSupportingText
import com.wap.wapp.core.model.survey.SurveyForm
import com.wap.wapp.core.model.user.UserRole
import kotlinx.coroutines.flow.collectLatest

Expand All @@ -41,11 +27,13 @@ internal fun SurveyScreen(
viewModel: SurveyViewModel,
navigateToSignIn: () -> Unit,
navigateToSurveyAnswer: (String) -> Unit,
navigateToSurveyCheck: () -> Unit,
) {
val context = LocalContext.current
val surveyFormListUiState = viewModel.surveyFormListUiState.collectAsStateWithLifecycle().value
val snackBarHostState = remember { SnackbarHostState() }
var isShowGuestDialog by rememberSaveable { mutableStateOf(false) }
var isGuest by rememberSaveable { mutableStateOf(false) }
var isManager by rememberSaveable { mutableStateOf(false) }

LaunchedEffect(true) {
viewModel.surveyEvent.collectLatest {
Expand Down Expand Up @@ -74,13 +62,18 @@ internal fun SurveyScreen(
is SurveyViewModel.UserRoleUiState.Success -> {
when (userRoleUiState.userRole) {
UserRole.GUEST -> {
isShowGuestDialog = true
isGuest = true
}

// 비회원이 아닌 경우, 목록 호출
UserRole.MEMBER, UserRole.MANAGER -> {
UserRole.MEMBER -> {
viewModel.getSurveyFormList()
}

UserRole.MANAGER -> {
viewModel.getSurveyFormList()
isManager = true
}
}
}
}
Expand All @@ -104,82 +97,19 @@ internal fun SurveyScreen(
is SurveyViewModel.SurveyFormListUiState.Success -> {
SurveyContent(
surveyFormList = surveyFormListUiState.surveyFormList,
isManager = isManager,
paddingValues = paddingValues,
selectedSurveyForm = viewModel::isSubmittedSurvey,
onSurveyCheckButtonClicked = navigateToSurveyCheck,
)
}
}
}

if (isShowGuestDialog) {
if (isGuest) {
SurveyGuestDialog(
onDismissRequest = { isShowGuestDialog = false },
onDismissRequest = { isGuest = false },
onButtonClicked = navigateToSignIn,
)
}
}

@Composable
private fun SurveyContent(
surveyFormList: List<SurveyForm>,
paddingValues: PaddingValues,
selectedSurveyForm: (String) -> Unit,
) {
LazyColumn(
verticalArrangement = Arrangement.spacedBy(8.dp),
modifier = Modifier
.padding(paddingValues)
.padding(horizontal = 16.dp),
) {
items(surveyFormList) { surveyForm ->
if (surveyForm.isAfterDeadline()) {
SurveyFormItemCard(
surveyForm = surveyForm,
selectedSurveyForm = selectedSurveyForm,
)
}
}
}
}

@Composable
private fun SurveyFormItemCard(
surveyForm: SurveyForm,
selectedSurveyForm: (String) -> Unit,
) {
Card(
colors = CardDefaults.cardColors(
containerColor = WappTheme.colors.black25,
),
modifier = Modifier
.fillMaxWidth()
.clickable { selectedSurveyForm(surveyForm.surveyFormId) },
) {
Column(
verticalArrangement = Arrangement.spacedBy(16.dp),
modifier = Modifier.padding(16.dp),
) {
Row(
modifier = Modifier.fillMaxWidth(),
) {
Text(
text = surveyForm.title,
color = WappTheme.colors.white,
style = WappTheme.typography.titleBold,
)
Text(
text = surveyForm.calculateDeadline(),
color = WappTheme.colors.yellow34,
style = WappTheme.typography.captionMedium,
modifier = Modifier.fillMaxWidth(),
textAlign = TextAlign.End,
)
}
Text(
text = surveyForm.content,
color = WappTheme.colors.grayBD,
style = WappTheme.typography.contentMedium,
)
}
}
}

0 comments on commit 06ff210

Please sign in to comment.