Skip to content

Commit

Permalink
Merge pull request #266 from School-of-Company/feature/232-program-st…
Browse files Browse the repository at this point in the history
…andard-network-error

🔀 :: (#232) - 연수, 일반 프로그램 신청에서 여러개를 한번에 보내지 못하고 같은 값으로 여러개가 보내지는 문제를 해결하였습니다.
  • Loading branch information
audgns10 authored Dec 23, 2024
2 parents 82aace2 + b3d15ba commit a282ed0
Show file tree
Hide file tree
Showing 7 changed files with 441 additions and 171 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ import com.school_of_company.design_system.theme.ExpoAndroidTheme
import com.school_of_company.expo.enum.TrainingCategory
import com.school_of_company.expo.view.component.ExpoAddTextField
import com.school_of_company.expo.view.component.ExpoSettingBottomSheet
import com.school_of_company.expo.view.component.ExpoStandardAddTextField
import com.school_of_company.expo.view.component.ExpoStandardSettingBottomSheet
import com.school_of_company.expo.viewmodel.ExpoViewModel
import com.school_of_company.expo.viewmodel.uistate.ImageUpLoadUiState
import com.school_of_company.expo.viewmodel.uistate.RegisterExpoInformationUiState
Expand Down Expand Up @@ -94,10 +96,6 @@ internal fun ExpoCreateRoute(
val coverImageState by viewModel.cover_image.collectAsStateWithLifecycle()
val trainingProgramTextState by viewModel.trainingProgramTextState.collectAsStateWithLifecycle()
val standardProgramTextState by viewModel.standardProgramTextState.collectAsStateWithLifecycle()
val startedTextState by viewModel.started.collectAsStateWithLifecycle()
val endedTextState by viewModel.ended.collectAsStateWithLifecycle()
val startedStandardTextState by viewModel.standardStarted.collectAsStateWithLifecycle()
val endedStandardTextState by viewModel.standardEnded.collectAsStateWithLifecycle()

var selectedImageUri by remember { mutableStateOf<Uri?>(null) }

Expand Down Expand Up @@ -152,25 +150,12 @@ internal fun ExpoCreateRoute(
is RegisterExpoInformationUiState.Success -> {
viewModel.registerTrainingProgramList(
expoId = (registerExpoInformationUiState as RegisterExpoInformationUiState.Success).data.expoId,
body = viewModel.trainingProgramTextState.value.map { title ->
TrainingDtoModel(
title = title,
startedAt = viewModel.started.value,
endedAt = viewModel.ended.value,
category = viewModel.categoryState.value.toString()
)
}
body = trainingProgramTextState
)

viewModel.registerStandardProgramList(
expoId = (registerExpoInformationUiState as RegisterExpoInformationUiState.Success).data.expoId,
body = viewModel.standardProgramTextState.value.map { title ->
StandardRequestModel(
title = title,
startedAt = viewModel.standardStarted.value,
endedAt = viewModel.standardEnded.value
)
}
body = standardProgramTextState
)
}
is RegisterExpoInformationUiState.Error -> {
Expand Down Expand Up @@ -222,15 +207,6 @@ internal fun ExpoCreateRoute(
onStandardProgramChange = viewModel::updateStandardProgramText,
onAddStandardProgram = viewModel::addStandardProgramText,
onRemoveStandardProgram = viewModel::removeStandardProgramText,
startedTextState = startedTextState,
endedTextState = endedTextState,
onStartedChange = viewModel::onStartedChange,
onEndedChange = viewModel::onEndedChange,
onTrainingCategoryChange = viewModel::updateCategory,
startedStandardTextState = startedStandardTextState,
endedStandardTextState = endedStandardTextState,
onStartedStandardChange = viewModel::onStandardStartedChange,
onEndedStandardChange = viewModel::onStandardEndedChange
)
}

Expand All @@ -254,27 +230,21 @@ internal fun ExpoCreateScreen(
onAddressChange: (String) -> Unit,
onLocationChange: (String) -> Unit,
onExpoCreateCallBack: () -> Unit,
trainingProgramTextState: List<String>,
onTrainingProgramChange: (Int, String) -> Unit,
trainingProgramTextState: List<TrainingDtoModel>,
onTrainingProgramChange: (Int, TrainingDtoModel) -> Unit,
onAddTrainingProgram: () -> Unit,
onRemoveTrainingProgram: (Int) -> Unit,
standardProgramTextState: List<String>,
onStandardProgramChange: (Int, String) -> Unit,
standardProgramTextState: List<StandardRequestModel>,
onStandardProgramChange: (Int, StandardRequestModel) -> Unit,
onAddStandardProgram: () -> Unit,
onRemoveStandardProgram: (Int) -> Unit,
startedTextState: String,
endedTextState: String,
onStartedChange: (String) -> Unit,
onEndedChange: (String) -> Unit,
onTrainingCategoryChange: (TrainingCategory) -> Unit,
startedStandardTextState: String,
endedStandardTextState: String,
onStartedStandardChange: (String) -> Unit,
onEndedStandardChange: (String) -> Unit
) {
val (openTrainingSettingBottomSheet, isOpenTrainingSettingBottomSheet) = rememberSaveable { mutableStateOf(false) }
val (openStandardSettingBottomSheet, isOpenStandardSettingBottomSheet) = rememberSaveable { mutableStateOf(false) }

var selectedTrainingIndex by remember { mutableStateOf<Int?>(null) }
var selectedStandardIndex by remember { mutableStateOf<Int?>(null) }

ExpoAndroidTheme { colors, typography ->
Column(
modifier = modifier
Expand Down Expand Up @@ -459,7 +429,7 @@ internal fun ExpoCreateScreen(
color = colors.black,
)

ExpoAddTextField(
ExpoStandardAddTextField(
trainingTextFieldList = standardProgramTextState,
onValueChange = { index, newState ->
onStandardProgramChange(index, newState)
Expand All @@ -468,7 +438,8 @@ internal fun ExpoCreateScreen(
onRemoveTextField = { index ->
onRemoveStandardProgram(index)
},
onTrainingSetting = {
onTrainingSetting = { index ->
selectedStandardIndex = index
isOpenStandardSettingBottomSheet(true)
},
placeHolder = "연수 종류를 입력해주세요."
Expand All @@ -491,7 +462,8 @@ internal fun ExpoCreateScreen(
onRemoveTextField = { index ->
onRemoveTrainingProgram(index)
},
onTrainingSetting = {
onTrainingSetting = { index ->
selectedTrainingIndex = index
isOpenTrainingSettingBottomSheet(true)
},
placeHolder = "연수 종류를 입력해주세요."
Expand Down Expand Up @@ -549,30 +521,41 @@ internal fun ExpoCreateScreen(

if (openTrainingSettingBottomSheet) {
Dialog(onDismissRequest = { isOpenTrainingSettingBottomSheet(false) }) {
ExpoSettingBottomSheet(
onCancelClick = { isOpenTrainingSettingBottomSheet(false) },
startedTextState = startedTextState,
endedTextState = endedTextState,
onStartedTextChange = onStartedChange,
onEndedTextChange = onEndedChange,
onCategoryChange = onTrainingCategoryChange,
onButtonClick = { isOpenTrainingSettingBottomSheet(false) }
)

val selectedTrainingItem = selectedTrainingIndex?.let { trainingProgramTextState[it] }

if (selectedTrainingItem != null) {
ExpoSettingBottomSheet(
onCancelClick = { isOpenTrainingSettingBottomSheet(false) },
onButtonClick = { isOpenTrainingSettingBottomSheet(false) },
trainingSettingItem = selectedTrainingItem,
onTrainingSettingChange = { updateItem ->
selectedTrainingIndex?.let { index ->
onTrainingProgramChange(index, updateItem)
}
},
)
}
}
}

if (openStandardSettingBottomSheet) {
Dialog(onDismissRequest = { isOpenStandardSettingBottomSheet(false) }) {
ExpoSettingBottomSheet(
onCancelClick = { isOpenStandardSettingBottomSheet(false) },
startedTextState = startedStandardTextState,
endedTextState = endedStandardTextState,
onStartedTextChange = onStartedStandardChange,
onEndedTextChange = onEndedStandardChange,
onButtonClick = { isOpenStandardSettingBottomSheet(false) },
onCategoryChange = {},
isTraining = false
)

val selectedStandardItem = selectedStandardIndex?.let { standardProgramTextState[it] }

if (selectedStandardItem != null) {
ExpoStandardSettingBottomSheet(
onCancelClick = { isOpenStandardSettingBottomSheet(false) },
onButtonClick = { isOpenStandardSettingBottomSheet(false) },
trainingSettingItem = selectedStandardItem,
onTrainingSettingChange = { updateItem ->
selectedStandardIndex?.let { index ->
onStandardProgramChange(index, updateItem)
}
}
)
}
}
}
}
Expand Down Expand Up @@ -604,14 +587,5 @@ private fun ExpoCreateScreenPreview() {
onStandardProgramChange = { _, _ -> },
onAddStandardProgram = {},
onRemoveStandardProgram = {},
startedTextState = "",
endedTextState = "",
onStartedChange = {},
onEndedChange = {},
onTrainingCategoryChange = {},
startedStandardTextState = "",
endedStandardTextState = "",
onStartedStandardChange = {},
onEndedStandardChange = {}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,19 @@ import com.school_of_company.design_system.icon.ImageIcon
import com.school_of_company.design_system.icon.LeftArrowIcon
import com.school_of_company.design_system.icon.WarnIcon
import com.school_of_company.design_system.theme.ExpoAndroidTheme
import com.school_of_company.expo.enum.TrainingCategory
import com.school_of_company.expo.view.component.ExpoAddTextField
import com.school_of_company.expo.view.component.ExpoSettingBottomSheet
import com.school_of_company.expo.view.component.ExpoStandardAddTextField
import com.school_of_company.expo.view.component.ExpoStandardSettingBottomSheet
import com.school_of_company.expo.viewmodel.ExpoViewModel
import com.school_of_company.expo.viewmodel.uistate.ImageUpLoadUiState
import com.school_of_company.expo.viewmodel.uistate.ModifyExpoInformationUiState
import com.school_of_company.model.model.expo.ExpoRequestAndResponseModel
import com.school_of_company.model.model.standard.StandardRequestModel
import com.school_of_company.model.model.training.TrainingDtoModel
import com.school_of_company.ui.toast.makeToast
import java.util.Locale.Category

@Composable
internal fun ExpoModifyRoute(
Expand Down Expand Up @@ -216,16 +222,25 @@ internal fun ExpoModifyScreen(
onIntroduceTitleChange: (String) -> Unit,
onAddressChange: (String) -> Unit,
onLocationChange: (String) -> Unit,
trainingProgramTextState: List<String>,
onTrainingProgramChange: (Int, String) -> Unit,
trainingProgramTextState: List<TrainingDtoModel>,
onTrainingProgramChange: (Int, TrainingDtoModel) -> Unit,
onAddTrainingProgram: () -> Unit,
onRemoveTrainingProgram: (Int) -> Unit,
standardProgramTextState: List<String>,
onStandardProgramChange: (Int, String) -> Unit,
standardProgramTextState: List<StandardRequestModel>,
onStandardProgramChange: (Int, StandardRequestModel) -> Unit,
onAddStandardProgram: () -> Unit,
onRemoveStandardProgram: (Int) -> Unit
) {
val (openTrainingSettingBottomSheet, isOpenTrainingSettingBottomSheet) = rememberSaveable { mutableStateOf(false) }
val (openTrainingSettingBottomSheet, isOpenTrainingSettingBottomSheet) = rememberSaveable {
mutableStateOf(
false
)
}
val (openStandardSettingBottomSheet, isOpenStandardSettingBottomSheet) = rememberSaveable {
mutableStateOf(
false
)
}

ExpoAndroidTheme { colors, typography ->
Column(
Expand Down Expand Up @@ -446,7 +461,7 @@ internal fun ExpoModifyScreen(
color = colors.black,
)

ExpoAddTextField(
ExpoStandardAddTextField(
trainingTextFieldList = standardProgramTextState,
onValueChange = { index, newState ->
onStandardProgramChange(index, newState)
Expand Down Expand Up @@ -509,20 +524,20 @@ internal fun ExpoModifyScreen(

ExpoStateButton(
text = "수정완료",
state = if (
modifyTitleState.isNotEmpty() &&
startedDateState.isNotEmpty() &&
endedDateState.isNotEmpty() &&
introduceTitleState.isNotEmpty() &&
addressState.isNotEmpty() &&
locationState.isNotEmpty() &&
trainingProgramTextState.isNotEmpty() &&
standardProgramTextState.isNotEmpty()
) {
ButtonState.Enable
} else {
ButtonState.Disable
},
state = if (
modifyTitleState.isNotEmpty() &&
startedDateState.isNotEmpty() &&
endedDateState.isNotEmpty() &&
introduceTitleState.isNotEmpty() &&
addressState.isNotEmpty() &&
locationState.isNotEmpty() &&
trainingProgramTextState.isNotEmpty() &&
standardProgramTextState.isNotEmpty()
) {
ButtonState.Enable
} else {
ButtonState.Disable
},
modifier = Modifier.fillMaxWidth()
) {
modifyCallBack()
Expand All @@ -538,12 +553,29 @@ internal fun ExpoModifyScreen(
Dialog(onDismissRequest = { isOpenTrainingSettingBottomSheet(false) }) {
ExpoSettingBottomSheet(
onCancelClick = { isOpenTrainingSettingBottomSheet(false) },
startedTextState = "",
endedTextState = "",
onStartedTextChange = {},
onEndedTextChange = {},
onCategoryChange = {},
onButtonClick = { /*TODO*/ }
onButtonClick = { isOpenTrainingSettingBottomSheet(false) },
trainingSettingItem = TrainingDtoModel(
title = "",
startedAt = "",
endedAt = "",
category = TrainingCategory.CHOICE.name
),
onTrainingSettingChange = {},
)
}
}

if (openStandardSettingBottomSheet) {
Dialog(onDismissRequest = { isOpenStandardSettingBottomSheet(false) }) {
ExpoStandardSettingBottomSheet(
onCancelClick = { isOpenStandardSettingBottomSheet(false) },
onButtonClick = { isOpenStandardSettingBottomSheet(false) },
trainingSettingItem = StandardRequestModel(
title = "",
startedAt = "",
endedAt = ""
),
onTrainingSettingChange = {},
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@ import com.school_of_company.design_system.component.modifier.clickable.expoClic
import com.school_of_company.design_system.icon.PlusIcon
import com.school_of_company.design_system.icon.XIcon
import com.school_of_company.design_system.theme.ExpoAndroidTheme
import com.school_of_company.model.model.training.TrainingDtoModel

@Composable
fun ExpoAddTextField(
modifier: Modifier = Modifier,
placeHolder: String,
trainingTextFieldList: List<String>,
onValueChange: (Int, String) -> Unit,
trainingTextFieldList: List<TrainingDtoModel>,
onValueChange: (Int, TrainingDtoModel) -> Unit,
onAddTextField: () -> Unit,
onRemoveTextField: (Int) -> Unit,
onTrainingSetting: () -> Unit
onTrainingSetting: (Int) -> Unit
) {

ExpoAndroidTheme { colors, typography ->
Expand Down Expand Up @@ -72,14 +73,14 @@ fun ExpoAddTextField(
Spacer(modifier = Modifier.padding(end = 12.dp))

BasicTextField(
value = text,
value = text.title,
onValueChange = { newState ->
onValueChange(index, newState)
onValueChange(index, text.copy(title = newState))
},
textStyle = typography.bodyRegular2,
cursorBrush = SolidColor(colors.main),
decorationBox = { innerTextField ->
if (text.isEmpty()) {
if (text.title.isEmpty()) {
Text(
text = placeHolder,
style = typography.bodyRegular2,
Expand All @@ -95,7 +96,7 @@ fun ExpoAddTextField(

TrainingSettingButton(
text = "연수설정",
onClick = onTrainingSetting
onClick = { onTrainingSetting(index) }
)

IconButton(onClick = { onRemoveTextField(index) }) {
Expand Down Expand Up @@ -130,11 +131,10 @@ fun ExpoAddTextField(
private fun ExpoAddTextFieldPreview() {
ExpoAddTextField(
placeHolder = "연수를 입력하세요.",
trainingTextFieldList = listOf(""),
trainingTextFieldList = listOf(),
onValueChange = { _, _ ->},
onAddTextField = { /*TODO*/ },
onRemoveTextField = { /*TODO*/ },
onTrainingSetting = { /*TODO*/ }

)
}
Loading

0 comments on commit a282ed0

Please sign in to comment.