Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc272057

Browse files
authored
fix: ws schedule top-down restriction (#2008)
Resolves:#1958Summary:The workspace schedule form no longer disables certain fields based onwhether or not a start time is filled out. Instead, we validate that astart time is provided if any of the days are checked.
1 parent88e8c96 commitc272057

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

‎site/src/components/WorkspaceScheduleForm/WorkspaceScheduleForm.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,22 @@ describe("validationSchema", () => {
5757
expect(validate).toThrowError(Language.errorNoDayOfWeek)
5858
})
5959

60+
it("disallows empty startTime when at least one day is set",()=>{
61+
constvalues:WorkspaceScheduleFormValues={
62+
...valid,
63+
sunday:false,
64+
monday:true,
65+
tuesday:false,
66+
wednesday:false,
67+
thursday:false,
68+
friday:false,
69+
saturday:false,
70+
startTime:"",
71+
}
72+
constvalidate=()=>validationSchema.validateSync(values)
73+
expect(validate).toThrowError(Language.errorNoTime)
74+
})
75+
6076
it("allows startTime 16:20",()=>{
6177
constvalues:WorkspaceScheduleFormValues={
6278
...valid,

‎site/src/components/WorkspaceScheduleForm/WorkspaceScheduleForm.tsx

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ dayjs.extend(timezone)
2727

2828
exportconstLanguage={
2929
errorNoDayOfWeek:"Must set at least one day of week",
30+
errorNoTime:"Start time is required",
3031
errorTime:"Time must be in HH:mm format (24 hours)",
3132
errorTimezone:"Invalid timezone",
3233
daysOfWeekLabel:"Days of Week",
@@ -93,6 +94,25 @@ export const validationSchema = Yup.object({
9394

9495
startTime:Yup.string()
9596
.ensure()
97+
.test("required-if-day-selected",Language.errorNoTime,function(value){
98+
constparent=this.parentasWorkspaceScheduleFormValues
99+
100+
constisDaySelected=[
101+
parent.sunday,
102+
parent.monday,
103+
parent.tuesday,
104+
parent.wednesday,
105+
parent.thursday,
106+
parent.friday,
107+
parent.saturday,
108+
].some((day)=>day)
109+
110+
if(isDaySelected){
111+
returnvalue!==""
112+
}else{
113+
returntrue
114+
}
115+
})
96116
.test("is-time-string",Language.errorTime,(value)=>{
97117
if(value===""){
98118
returntrue
@@ -192,7 +212,7 @@ export const WorkspaceScheduleForm: FC<WorkspaceScheduleFormProps> = ({
192212
</Link>
193213
</>,
194214
)}
195-
disabled={isLoading||!form.values.startTime}
215+
disabled={isLoading}
196216
InputLabelProps={{
197217
shrink:true,
198218
}}
@@ -210,7 +230,7 @@ export const WorkspaceScheduleForm: FC<WorkspaceScheduleFormProps> = ({
210230
control={
211231
<Checkbox
212232
checked={checkbox.value}
213-
disabled={!form.values.startTime||isLoading}
233+
disabled={isLoading}
214234
onChange={form.handleChange}
215235
name={checkbox.name}
216236
color="primary"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp